Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scp command change using alias

I frequently use

scp -r id@remoteserver_ip:/Data_folder/

to download data a folder from a remote supercom server.

Having to write the same every time is rather tiresome.

Does anybody know easy to use this command using alias? Consider that Data_folder will be changed every time.

like image 935
user4914499 Avatar asked Aug 11 '26 20:08

user4914499


2 Answers

You should consider setting up ssh config:

Host myServer
    HostName remoteserver_ip
    User id

And perhaps add a identity file as well to avoid having to type password:

Host myServer
    ...
    IdentityFile ~/.ssh/my_id

Now you can write:

scp -r myServer:/something

Of cause you can - as suggested by other answers - add a function to your ~/.bashrc:

my_scp() {
  scp -r myServer:"$1"
}

And then call:

my_scp /something
like image 76
Andreas Louv Avatar answered Aug 14 '26 11:08

Andreas Louv


Alias can't replace a part of a word. You can create a function, though:

myscp () {
    scp -r id@remoteserver_ip:/"$1"/
}

Then, just call myscp Data_folder.

Also, scp (at least on my system) needs the destination folder, too. You can add . as then next parameter to the command in the function, or use "$2" and specify it on the command line when running the function.

like image 21
choroba Avatar answered Aug 14 '26 10:08

choroba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!