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.
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
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.
You can't setup an alias to take an argument. So you'll have to create a function and then you'll be able to alias scp
to that
function super_scp() {
scp -r id@remoteserver_ip:${1} ${2}
}
alias scp=super_scp
Then you'll be able to use it like:
scp /path/to/folder /destination
You can make a bash file in one of your $PATH folders.
#! /bin/bash
scp -r id@remoteserver_ip:"$1" "$2"
Let's call the script myscp.
Instead of writing the whole line you wrote, you can write
myscp /home/file.txt /home/file2.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.