1

I want to copy some files/folders to a USB Flash Drive, SSD, or HDD after I connect them to my laptop. I don't want to detect the USB, do extra stuff, etc.. I just want to run a script from my terminal, which copies specified files to a specified external drive.

Earlier I have written

alias onetbeans='sudo /usr/local/netbeans-8.2/bin/netbeans'

in my .bashrc file to open netbeans by just writing onetbeans.

I wished to know if there is anything similar I can do for copying files? I would only copy some specific files/folder which I can mention.

Example:

cp -R [folder to copy] /media/shray/[name of usb/hard drive]  

Now, my [folder to copy] is constant. But how do I take care of different names a usb can take? For example, if I need to copy to a usb named "myusb" then I can write

alias customcopy='cp -R ~/Desktop/copyFolder /media/usb/myusb/'

But how do I take care of changing USB drive names?

  • 1
    Is it always the same USB-drive or will they vary? – Fiximan May 23 '19 at 7:16
  • they will vary @Fiximan – Shray May 24 '19 at 6:34
1

You can create a bash function in your .bashrc for this.

customcopy() {
    cp -R ~/Desktop/copyFolder/ "$1"
}

After sourcing your .bashrc, you can use it like this:

customcopy /media/usb/myusb/
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.