How to resolve “mv: Argument list too long”

I have 1,30,000 files to move from one directory to another, When I ran command

# mv *.txt test

Oh!! There is an error

mv: Argument list too long.

What to do? I did it but in different way. I ran command

#find . -maxdepth 1 -name ‘*.txt’ -exec mv ‘{}’ test \;

Here

.                      defines search directory

-maxdepth     disables recursive search and searches only in the current directory. It allows you to control

how deep into sub directories it will recurs. With ‘-maxdepth’ 1 it will only search in current

directory.

-name             string to be searched

-exec              Applies a command to set of file that has been searched

{}                      Inserts each found file into given command after -exec

\;                     Indicates the exec command line has ended

The above example searches for *.txt files in current directory and moves it to the test directory.

More:    http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm

Leave a Reply