Linux Shell |
Last Updated March 2014
|
Copy without overwrite (ignore existing)
yes n | cp -i src dest
Mount remote folder over SSH
sudo apt-get install sshfs mkdir ~/folder sshfs user@server:/remote/path/to/folder ~/folder
TAR+GZIP directory recursively
tar -zcvf archive.tar.gz folder
Afterwards, untar and gunzip with the following:
tar -zxvf archive.tar.gz
References:
Watch file size grow
Here's a nifty little command you can run to watch the size of a file grow (such as if it's being transferred over SFTP by another process like CRON):
watch -n 5 "du -h filename"
Start program over SSH w/o ending by disconnect
Some things take a while and when the SSH connection times out it will quit all running programs in that session. I found this simple method to run those long commands and disconnect without killing them:
Later ...
Reference: http://superuser.com/questions/134554/how-to-keep-program-running-after-ssh-disconnection
- SSH to server
- Run "screen" command
- Start whatever things you want
- Press CTRL+A, CTRL+D to detach from screen session
Later ...
- SSH to server
- Run "screen -r" to reattach to screen session
Reference: http://superuser.com/questions/134554/how-to-keep-program-running-after-ssh-disconnection
SCP: Copy file via SSH
scp -P port hostname:/remote/path/file.txt /local/path
SFTP shell script
- http://stackoverflow.com/questions/5386482/how-to-run-the-sftp-command-with-a-password-from-bash-script
- http://stackoverflow.com/questions/19531699/sftp-file-manipulation-using-shell-script
Cancel stuck SSH session
Press ~. (TILDE + PERIOD). You may have to press ENTER before that. CTRL+C, as you may have noticed, does not end a session that needs to timeout due to a broken pipe. This often happens to me when I put my laptop in suspend and then return to it later.