I have files named


I want to copy these files from one folder to another in Linux. The problem is there are also many other files in the directory. I want to do it by command line because the directory have a lots of file.

cp file_1_supply.csv /home/user/destination

usually I use this for copy but how to use this in a loop?

  • 5
    Why a loop? cp file_*.csv /home/user/destination should work. – icarus Jan 17 '17 at 0:31

If you only want to copy file_1-file_30:

cp file_{1..30}_supply.csv /home/user/destination
| improve this answer | |
  • I edited the question.So actually I think I have to use cp file_{1..30}_supply.csv /home/user/destination – RKR Jan 17 '17 at 0:48

Use -t flag to designate the destination

cp -t /home/user/destination file_*_supply.csv 

For specific range, you can also use find command:

find -name "*file_[1-30]*" -exec cp "{}" /home/user/destination \;
| improve this answer | |

I recommend to use this command

cp * /path/to/destination/

this is the easiest way to copy many files but if you want to specify files I suggests @Flohe's answer

| improve this answer | |
  • That wouldn't work because it will copy all the files, however as mentioned, there are other files in the directory that shouldn't be copied. – Zumo de Vidrio Jan 17 '17 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.