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
A:
$ 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
.
The MYYN
2010-09-10 17:40:57
Thanks, but I need to know that this will work for sure, I cannot lose/misplace any of these files, and don't have much knowledge in this area...
sassy_geekette
2010-09-10 17:44:17
This works if I go into each subfolder and run the command, but I'm looking for something that will look in each subdirectory then move the files up, a command I wouldn't have to run multiple times in each folder.
sassy_geekette
2010-09-10 17:53:30
@sassy_geekette: `|` is a pipe, connecting two programs via their input and output. So to test, just execute `find . -name *.pdf` alone (this won't copy or move anything). If this matches the files you are interested in, the do the following: `find . -name *.pdf | xargs -I {} echo {}`. The output should be the same. Still, this won't move or copy anything. Then `cp` or `mv`.
The MYYN
2010-09-10 17:55:09
Worked perfectly, thanks a lot!
sassy_geekette
2010-09-10 17:58:07