Help - Search - Members - Calendar
Full Version: Moving Files With Bash
Linuxhelp > Support > Technical Support
anon
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?

dishawjp
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.
Corey
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 .
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.