How to copy multiple files from a different directory using cp?
Solution 1:
cp ../dir5/dir4/dir3/dir2/file[1234] .
or (in Bash)
cp ../dir5/dir4/dir3/dir2/file{1..4} .
If the file names are non-contiguous, you can use
cp ../dir5/dir4/dir3/dir2/{march,april,may} .
Solution 2:
If all the files you want to copy are in the pattern of file{number}{othertext}
, you could use something like:
cp ../dir5/dir4/dir3/dir2/file[0-9]* .
Note that this will copy file5
, but it will also copy file0abc
.
If you would like to copy ONLY those four files (and not the {othertext} ones), you can use:
cp ../dir5/dir4/dir3/dir2/file[1-4] .
Note that while this looks like part of a regular expression, it is not.
Solution 3:
Try this one:
cp ../dir5/dir4/dir3/dir2/file{1..4}