I want to copy several files from one folder to another. How do I do it from the shell command prompt?
Consider that folder1 contains ten files (e.g. file1, file2, abc, xyz, etc.). I am currently doing the following in order to copy two files from one folder to another:
cp /home/ankur/folder/file1 /home/ankur/folder/file2 /home/ankur/dest Typing the full path into the command line for both the files is annoying.
What comes to my mind is regex, but I don't quite know how to do it.
Any help will reduce my RSI ;-)
4 Answers
I guess you are looking for brace expansion:
cp /home/ankur/folder/{file1,file2} /home/ankur/dest take a look here, it would be helpful for you if you want to handle multiple files once :
tab completion with zsh...

Use wildcards:
cp /home/ankur/folder/* /home/ankur/dest If you don't want to copy all the files, you can use braces to select files:
cp /home/ankur/folder/{file{1,2},xyz,abc} /home/ankur/dest This will copy file1, file2, xyz, and abc.
You should read the sections of the bash man page on Brace Expansion and Pathname Expansion for all the ways you can simplify this.
Another thing you can do is cd /home/ankur/folder. Then you can type just the filenames rather than the full pathnames, and you can use filename completion by typing Tab.
You can use brace expansion in bash:
cp /home/ankur/folder/{file1,abc,xyz} /path/to/target 2Try this simpler one,
cp /home/ankur/folder/file{1,2} /home/ankur/dest If you want to copy all the 10 files then run this command,
cp ~/Desktop/{xyz,file{1,2},next,files,which,are,not,similer} foo-bar 0