4

Hi i want to run a linux command that automates a scp with the location of origin that varies and the destination location that remains contant. For example -

scp 123.txt [email protected]:~/

the destination ([email protected]) will always be the same, however the file name (123.txt) will always be different.

I would like to run this entire scp command (scp 123.txt [email protected]:~/) without typing the destination location

note: ([email protected] in this case might seem short however i have a much more complex destination that is cumbersome to type out every single time)

3 Answers 3

12

Try using a function instead of an alias. Put the following function in your .bashrc file.

function do-scp() {
    scp "$1" [email protected]:~/
}

And thus you invoke it as follows:

do-scp 123.txt
Sign up to request clarification or add additional context in comments.

Comments

1

In case you would like to use the shortcut with a slightly different destination on the remote location called 'xyz', you could add in your ~/.bashrc:

function scp_xyz() { scp $1 [email protected]:"${2}" }

And then use:

scp_xyz 123.txt /different_destination_on_xyz/

Comments

0

You can define a function in bash, for example:

my_scp()
{
  scp $1 [email protected]:~/
}

and use

$my_scp 123.txt

You can put them in ~/.bash_profile so that they are always available

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.