Monday, November 3, 2014

move all files in current directory into a subdirectory in the current directory

I needed to move all the files in the current working directory (mount point) into a sub-directory. I hope this helps others, and me in the future.

Use the -maxdepth 1 option to find, instead of the "*" and ".*", something like this:

Code:
mkdir ./dest_dir
find . -maxdepth 1 | grep -v dest_dir | xargs -i mv {} ./dest_dir
http://www.linuxquestions.org/questions/linux-newbie-8/move-all-files-in-current-directory-into-a-subdirectory-in-the-current-directory-637150/


  -i,--replace=[R]             Replace R in initial arguments with names
                               read from standard input. If R is
                               unspecified, assume {}

http://community.spiceworks.com/how_to/show/98496-move-all-files-in-current-directory-into-a-subdirectory-in-the-current-directory

---------

addition per spiceworks! (Leecallen)

Nice, and useful.
Slight simplification - explicitly tell find that you are only interested in files, and then remove the grep command:

     find . -maxdepth 1 -type f | xargs -i mv {} ./dest_dir;

or just for kicks:

     find . -maxdepth 1 -type f -exec mv {} ./dest_dir \;