I want to copy all pdf files into another directory

andrej benedičič 07/11/2018. 5 answers, 54 views

Linux users! I'm having a issue: I have all pdf files in directoryDownloads, but I want it to copy all the files in subfolder \Download\BOOKS\. How would I copy all files with for loop?

for files in ...

5 Answers

Trasicio Maina 07/11/2018.

I don't know about for loops (unless you write a C program to achieve this) but this line should do it:

 cp -v ~/Downloads/*.pdf ~/Downloads/BOOKS/

The CP is copy and the * is for wildcard to select anything ending in .pdf in that directory.

Kevin 07/11/2018.

not with a for loop but this should work to move the files.

mv /home/username/Downloads/*.pdf /home/username/Downloads/BOOKS

Use this to make a copy of the files:

cp /home/username/Downloads/*.pdf /home/username/Downloads/BOOKS

Ogre55 07/11/2018.

A simple for loop will work, but is much more complicated than it needs to be.

for FILE in ~/Downloads/BOOKS/*; do
  cp $FILE /new/directory/

This will copy all files in the BOOKS directory to /new/directory

Mc Jorch 07/11/2018.

I can't comment to the answer above :( , but for "copying" you should use the command cp and then the same path as mentioned /home/yourUsername/Downloads/BOOKS

Kulfy 07/11/2018.

I don't think that you require for loop just for copying files. You can copy files using:

cp /home/username/Downloads/*.pdf /home/username/Downloads/BOOKS

But if you still want to use for loop, you can also write the below code:

cd /home/username/Downloads
for F in *.pdf
   cp $F /home/username/Downloads/BOOKS

Related questions

Hot questions


Popular Tags