Reputation: 61
Imagine that i have lots of sub-directory in a sub-directory in a directory I wanted to copy all the .tar and .tar.bz2 extension files from all the sub-directories into another directory.
I used
$find /home/apple/mango -name *.tar -exec cp {} ./kk \;
but it copies only once from a sub directory and stops , it doesn't find files which are in other sub directories or go inside a sub directories and find them. I want to do it recursively
Upvotes: 0
Views: 114
Reputation: 786289
You may use:
find /home/apple/mango -name '*.tar*' -execdir cp {} /full/path/to/kk \;
Note how name pattern is quoted to avoid shell expansion even before find
command executes.
In the absence of quoting *.tar
is expanded to some file.tar
which is present in current directory and find
stop right there because file.tar
is not found in sub directories. By quoting glob pattern we make sure that find
command gets literal pattern to search the sub directories.
Upvotes: 3