Powered By

Powered by Blogger

Jumat, 15 Oktober 2010

Copy / Paste Files From The Command Line [Bash Alias]

Here is a cool bash alias which you can place you your ~/.bashrc file to be able to copy and paste from the command line:

ccopy(){ for i in $*; do cp -a $i /tmp/ccopy.$i; done }
alias cpaste="ls -d /tmp/ccopy* | sed 's|[^\.]*.\.||' | xargs -I % mv /tmp/ccopy.% ./%"


To use it, copy the above code, open your ~/.bashrc file:
gedit ~/.bashrc

Then paste the code at the bottom of the file, save it and run the following command:
source ~/.bashrc

What's cool about this is that you can copy a file, then copy another file (so you can do this using 2 or more separate commands) and paste all the files you've previously copied using one command. Here's an example on how it works:

Copy paste command line


To use it, copy with "ccopy SOMEFILE ANOTHERFILE" - you can run this as many times as you want and all the files you've copied will be stored. Then paste all the files you've copied with "cpaste".


Please note that it only works for files (doesn't work for folders).


Update: Deepak Mittal (see the comment below) modified the code to also works with folders - many thanks! However, please note that it doesn't work with spaces!


I've found the original code HERE, but I've tweaked it so that it supports copying multiple files at once.

Tidak ada komentar:

Posting Komentar