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.

Michael Lindman
  • 1,722
  • 2
  • 17
  • 23
lunchboy
  • 33
  • 1
  • 3
  • 1
    As your google is broken ... http://unix.stackexchange.com/questions/81349/how-do-i-use-find-when-the-filename-contains-spaces and http://superuser.com/questions/80033/command-line-wizardry-spaces-in-file-names-with-find-grep-xargs – Panther Oct 29 '15 at 16:19

1 Answers1

6

You can simply use -exec option of find command

find . -iname '*.acc' -exec cp {} <dest folder> \;
M.Fooladgar
  • 499
  • 4
  • 8