Code Self Study Forum

Useful command-line tools for managing files on remote servers

Related to some recent discussions at meetups, here are a few command-line tools that make working with servers easier:

ssh – connect to a remote server

$ ssh -p 22 <username>@<ip_address>

scp – copy files between computers

scp is is a good alternative to FTP clients.

Copy files from a remote server to current location on the local computer:

$ scp -r -P 22 <username>@<ip_address>:/home/<username>/path/to/dir/* .

Copy files from the current directory to a remote server:

$ scp -r -P 22 . <username>@<ip_address>:/home/<username>/path/to/dir/

rsync – synchronize directories between computers

Synchronize a remote directory to a local directory over SSH:

$ rsync -avzhe ssh <username>@<ip_address>:/home/<username>/path/to/dir/* .

If the download gets interrupted, it won’t need to start over.

If downloading a large number of files, a small shell script like this will create a notification (on Linux) that displays the progress every minute:

while true; do                                                                                                                                                                                           
    notify-send 'Downloaded files' "$(ls -alR | wc -l) of <total_number>"
    sleep 60
done

(Run ls -alR | wc -l on the remote server to find the number to insert in <total_number>.)

1 Like