Laziness: SCP Alias

less than 1 minute read

I often find myself needing to download files to my local box via SCP. Which means entering the hostname, the path, and the filename in to my terminal window. However, I’m really lazy, if I can’t auto complete it or cut and paste it, I’m not happy. Enter this simple Bash function:

to_scp() { echo scp "$USER@`hostname -f`:$PWD/$@"; }

and this tcsh alias:

alias to_scp 'echo scp $user@`hostname -f`:$cwd/\!^'

In either shell, typing:

to_scp filename

outputs something like scp user@net.example.com:/var/www/filename, which you can then cut and paste into you local window sticking a . or a directory on the end:

scp user@net.example.com:/var/www/filename .

Added bonus: if you leave the filename off, you get just the directory, scp user@net.example.com:/var/www/, handy for uploading:

scp filename user@net.example.com:/var/www/

Of course, if you followed my previous tip about Remote SSH Usernames you can further reduce the aliases to:

to_scp() { echo scp "`hostname -f`:$PWD/$@"; }

and:

alias to_scp 'echo scp `hostname -f`:$cwd/\!^'

Laziness for the win!

Comments