Gara  Dash
Gara Dash

Reputation: 93

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.

Upvotes: 7

Views: 9019

Answers (2)

anubhava
anubhava

Reputation: 784988

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

Upvotes: 11

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798526

*.* matches all filenames that have a dot in the second or further position. It will not match filenames that do not have a dot. Using * instead will match all filenames that do not start with a dot.

Upvotes: 0

Related Questions