Basic SSH Goodies That Every Webmaster Should Know
You can use Putty or Linux Terminal to SSH to your server. While there are thousands of SSH commands available and it’s hard to master all of them in a short period, mastering some SSH goodies would be a good first step to start learning SSH.
However, it’s not recommended to play around with the SSH commands you can find on the internet on your critical production server.
Create a new file
Command: # touch newfile.txt
Find a file contain keywords
Command: # grep -lr “keywords” /YOUR_PATH/YOUR_FOLDER
Copy a file or folders
For copy a file:
Command: # cp <SOURCE> <DESTINATION>
For copy a folder, you have to use the -r flag:
Command: # cp -r<SOURCE> <DESTINATION>
Move a file or folders
Moving a file is similar to copy a file, just swap the command “cp” with “mv” will do
For moving a file:
Command: # mv <SOURCE> <DESTINATION>
For moving a folder, you have to use the -r flag:
Command: # mv -r<SOURCE> <DESTINATION>
Download/Upload a file
You can use this command to download or upload a file from/to the server.
To download a file:
Command: # scp username@ipaddress:/PATH_TO_FILE /PATH_TO_DESTINATION
To upload a file:
Command: # scp /PATH_TO_DESTINATION username@ipaddress:/PATH_TO_FILE
Zip a file
This will zip the myfile.txt to myfile.zip
Command: # zip myfile.zip myfile.txt
This will zip the entire myfolder to myfile.zip
Command: # zip -r myfile.zip myfolder
To unzip a file:
Command: # unzip myfile.zip
To Compress a file or foler to a .tar file
To compress one file or folder to a tar file:
Command: # tar -cvf file.tar filename
To extract a tar file:
Command: # tar -xvf file.tar