Move all files of same type in multiple directorie

2019-03-22 02:40发布

问题:

I have about 2000 subfolders in one folder, in each of these folders there are .pdf files. I need a unix command that will move all these files up one folder.

回答1:

$ cd thefolder # which contains the subfolders and where the PDFs should land
$ find . -name *.pdf | xargs -I {} cp -iv {} .

# find all files
# which end in .pdf
# recursively from
# the current folder
#                    |
#                      for each emitted line
#                      copy the output (captured by {}) to 
#                      the specified path ('.' is the current directory)
#                      copy should be verbose and should ask,
#                      in case a file would be overwritten

This should copy your files into /thefolder/. If you want to move them replace cp with mv.