Move all files of the same type to several directories in one folder

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

+3
source share
1 answer
$ 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 to /thefolder/. If you want to move them, replace cpwith mv.

+10
source

Source: https://habr.com/ru/post/1764195/


All Articles