How to copy multiple files from another directory using cp?

I want to copy several files from a specific directory as soon as I get to another directory. To clarify, I want to do the following immediately (one command):

cp ../dir5/dir4/dir3/dir2/file1 . cp ../dir5/dir4/dir3/dir2/file2 . cp ../dir5/dir4/dir3/dir2/file3 . cp ../dir5/dir4/dir3/dir2/file4 . 

I can not use cp ../dir5/dir4/dir3/dir2/* . because dir2 has n files (n>4)

By the way, I use bash .

Thank.

+42
linux bash cp
Mar 28 '12 at 21:20
source share
3 answers
 cp ../dir5/dir4/dir3/dir2/file[1234] . 

or (in bash)

 cp ../dir5/dir4/dir3/dir2/file{1..4} . 

If the file names are not contiguous, you can use

 cp ../dir5/dir4/dir3/dir2/{march,april,may} . 
+71
Mar 28 '12 at 21:22
source share

If all the files you want to copy are in the file{number}{othertext} , you can use something like:

 cp ../dir5/dir4/dir3/dir2/file[0-9]* . 

Note that this will copy file5 , but also copy file0abc .

If you want to copy ONLY these four files (and not {other texts}), you can use:

 cp ../dir5/dir4/dir3/dir2/file[1-4] . 

Note that although this looks like part of a regular expression, it is not.

+5
Mar 28 '12 at 21:24
source share

Try the following:

  cp ../dir5/dir4/dir3/dir2/file{1..4} 
+3
Mar 28 2018-12-21T00:
source share



All Articles