2

I have files named

file_1_supply.csv
file_2_supply.csv
file_3_supply.csv
.......
file_30_supply.csv

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?

1
  • 5
    Why a loop? cp file_*.csv /home/user/destination should work. Commented Jan 17, 2017 at 0:31

3 Answers 3

8

If you only want to copy file_1-file_30:

cp file_{1..30}_supply.csv /home/user/destination
1
  • I edited the question.So actually I think I have to use cp file_{1..30}_supply.csv /home/user/destination Commented Jan 17, 2017 at 0:48
1

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 \;
0

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

1
  • 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. Commented Jan 17, 2017 at 8:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.