Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

Advanced DNS Management
New ZoneEdit. New Managment.


Sign Up Now
Reply to this topicStart new topic
> Moving Files With Bash
post Jul 28 2005, 09:26 AM
Post #1

Whats this Lie-nix Thing?

Group: Members
Posts: 11
Joined: 3-July 04
Member No.: 3,277

In my home directory, I have a folder which contains a few hundred other folders. Each of these folders contains a single folder that conains another single folder. I would like to move the files at the bottom of that tree up two folders and delete the empty folders that I won't need any longer. How can I do this?

Go to the top of the page
+Quote Post
post Jul 29 2005, 09:16 AM
Post #2


Group: Members
Posts: 56
Joined: 8-April 04
Member No.: 2,734

There are a lot of ways, but without the actual directory names, you could do this:

cd <dir_name>
(where <dir_name> is the directory holding the files you want to move up two levels.)
mv * ..
cd ..
mv * ..
cd ..
rm -rF <other_dir>
(where other_dir is the name of the directory one level above the original directory the files were in)

With actual full directory names, this could be shortened a lot.

Registered Linux User 294493
Go to the top of the page
+Quote Post
post Jul 29 2005, 10:26 AM
Post #3

Its GNU/

Group: Admin
Posts: 1,254
Joined: 21-September 02
From: St John's, Newfoundland, Canada
Member No.: 3

I think he wants a more automated way, seeing that there are hundreds of directories. You could probably do something with for loops, but i would need more information such as the directory naming scheme, etc.

$> for i in $(ls)
> do
> cd $i/x/y
> mv * ../..
> cd ../../..
> done

This will not work by itself, it's just something to work off of, depending on your directory naming .

Corey Quilliam
(former) Administrator

Want to help out Check out our Linuxhelp Wiki and see if there are some articles you would like to submit!!

Ubuntu 8.04 64-bit - Work Laptop (HP-Compaq NC6400 Core2)
Kubuntu 8.04 64-bit - Desktop (HP m8120n QuadCore)
Ubuntu 6.04 - Server (I'm not upgrading this baby until support runs out in 2012) (Some old POS dell)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 20th July 2018 - 09:48 AM