Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX Terminal command to move all files in directory

i'm at the OSX terminal now and try to move a lot of files from ~/Desktop/dir/ to ~/Desktop/dir/dir2.

Command

mv *.* ~/Desktop/dir/dir2

doesn't work.

like image 794
Gara Dash Avatar asked Nov 24 '14 05:11

Gara Dash


1 Answers

You're getting "too many argument" because there are probably too many files in ~/Desktop/dir/ that that are allowed by glob matching pattern on command line.

To move all files from ~/Desktop/dir/ to ~/Desktop/dir/dir2 use this find instead:

find ~/Desktop/dir/ -type f -execdir mv '{}' ~/Desktop/dir/dir2 \;

Or to move everything including files and directories use:

cd ~/Desktop/dir/
find . -path './dir2' -prune -o ! -name . -exec mv '{}' ./dir2 \;

i.e. other than dir2 and . move everything to ~/Desktop/dir/dir2

like image 82
anubhava Avatar answered Sep 28 '22 12:09

anubhava