Here are some handy commands for connecting to servers and copying files about. These are all for Linux terminal / bash shell
Do cool things with ssh; log in & run command, find files in dir
# log into server
ssh [email protected] -Y
# -X Enables X11 forwarding. <- use this to enable X11 graphical windows, but this will eventually time out & you'll lose the X11 connection
# -Y Enables trusted X11 forwarding. <- this one preserves your X11 connection while you're logged in
# run a command on the remote server
ssh [email protected] find /path/to/server/source -maxdepth 1 -type f
# run a lot of commands on the remote server and write the output to a file, using a heredoc
# also demo variable expansion in heredoc
my_var="foo"
ssh [email protected] > server_info.txt << EOF
echo "$my_var"
sys_info="\$(uname -a)"
echo "\$sys_info"
EOF
Use rsync to copy files from a server to your local machine
rsync -avzheRn --progress --max-size=500K -e "ssh -p 501" [email protected]:/path/to/server/source/ /path/to/local/destination/
# rsync /source/ /destination/
# "ssh -p 22" = connect via ssh, port 22
# -n, --dry-run show what would have been transferred
# -a, --archive archive mode; same as -rlptgoD (no -H), <- preserves timestamps
# -v, --verbose increase verbosity
# -z, --compress compress file data during the transfer
# -h, --human-readable output numbers in a human-readable format
# -e, --rsh=COMMAND specify the remote shell to use
# -R, --relative use relative path names
# --progress show progress during transfer
# -L, --copy-links transform symlink into referent file/dir <- very good if you have symlinks and want the original file
Copy files and dirs with scp
scp -prP 501 [email protected]:/path/to/server/source/\{dir1,dir2\} /path/to/local/destination/
# -P port
# -p Preserves modification times, access times, and modes from the original file.
# -r Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.