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,
. : 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.
# 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,
. : 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.
No comments:
Post a Comment