Suppose, there are 1,30,000 files to move from one directory to another, what will happen?
# mv *.txt test
Oh!! There is an error:
mv: Argument list too long.
What to do? Simple answer is to use find command:
# find . -maxdepth 1 -name '*.txt' -exec mv '{}' test \;
Here,
| Option | Description |
|---|---|
. | Defines search directory |
-maxdepth | Disables recursive search. With -maxdepth 1 it will only search in current directory |
-name | String to be searched |
-exec | Applies a command to set of files that have 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.
Originally published May 16, 2010 on jaymspatel.blogspot.com