3

I would like to copy all files with a certain extension that are in sub directories to a different folder. I don't want to maintain the directory structure, I just want to copy all files found to a different folder.

I used this command to do it:

cp `find . -name "*.aac"` /media/moasad/New\ Volume/Media\ files/Avengers/Aud/aac/

However, I noticed that If it runs into folders or files with spaces in them the cp function doesn't know what to do and I get an error something like this:

cp: cannot stat ‘./Temporary_Items/martin/Problem’: No such file or directory
cp: cannot stat ‘Files/nav-YCA136843.aac’: No such file or directory

Notice that its one file: ./Temporary_Items/martin/Problem Files/nav-YCA136843.aac

But because of the space in "Problem Files", it's confused.

1

1 Answer 1

6

You can simply use -exec option of find command

find . -iname '*.acc' -exec cp {} <dest folder> \;
1
  • 1
    Or ... -exec cp -t <dest folder> {} +, so that it copies many files together.
    – muru
    Dec 20, 2015 at 17:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.