A Web.com Partner
Sign Up / Log In
Online Support Web Hosting

What Are the Common SSH Commands

In this article, we’ll introduce you to the common SSH commands that you’ll be using to control a server remotely.

Please note that, before using these commands, your server must be set up accept SSH connections and you must have connected to your server either using a terminal application or using PuTTY. For more information on how to set this up, please see one of the following articles on using SSH:

Important: It is very easy to make mistakes when using shell access. Make sure you have created a full backup of your files before attempting any changes.

Before using a command, you can check its documentation by entering the following:

man command

These are some of the common commands used in SSH, but not limited to:

To change folders:

cd pathname/folder/subfolder

To go up one level in nested directories:

cd ../

To go to the root directory:

cd /

To return to the previous directory:

cd -

To show the directory you are currently working in:

pwd

To show the contents of the working directory:

ls -alh

File Commands:

To read the contents of a text file:

less filename

To show the last 10 lines of a file:

tail -f filename

To search the contents of files (for "example"):

grep "example" filename

To search all files and subdirectories in a directory (for "example"):

grep -R "example" directory/

To copy a file:

cp original-file-name.txt new-file-name.txt

To copy files between directories:

cp original-file-name.txt ../../newfolder/new-file-name.txt

To copy all files from one directory to another:

cp files/* ../end/

To move a file from one directory to another:

mv currentfolder/filename.txt ../newfolder/filename

To make a copy of a file with a new name in the working directory:

mv current-file-name.txt new-file-name.txt

To move a directory up one level:

mv folder/ ..

To change file permissions:

chmod 755 index.html

The 755 is the previous sample corresponds to specific permissions that files can have. Here is a list of those permissions:

7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied

The first number is for the owner, second for the group, and third for everyone.

To change the owner of a file (be sure to replace "domainuser" with the appropriate user):

chown domainuser index.html

To change the group of a file (be sure to replace "groupname" with the appropriate group):

chgrp groupname index.html

To copy a file to a different directory:

cp file.txt folder/file.txt

To copy a file to the same directory

cp file.txt file.txt_old

To copy an entire directory:

cp -R folder folder2

To create or edit a file:

nano file.txt

To create a new file:

touch newfile.txt

To create a zip archive:

zip -r file-name.zip foldername

To unzip a zip archive:

unzip filename.zip

To create a tar.gz archive:

tar czvf archive.tar.gz directory-or-file/

To decompress a tar.gz archive:

tar -xzf archive.tar.gz

To back up a database:

mysqldump -u database_user -p database > backup.sql

To restore a database from a backup:

mysql -u database_user -p database < name_of_backup.sql

To delete a file (this must be confirmed by pressing the y key and pressing enter in response to the prompt that comes up):

rm file.txt_old

To delete a file without being prompted:

rm -rf file.txt_old

To delete an entire folder and all its subfolders and contents without being prompted:

rm -rf /old/folder

Important: This is irreversible. Be sure that you have created proper backups before using this command. We will NOT be able to reverse your deletions.

Server Commands:

To change the password for current user:

passwd

To change the password for another user:

passwd username

To log into MySQL:

mysql

To show currently active server processes:

ps -auxf

To show live processes and memory use:

top

To restart Apache (CentOS):

service httpd restart

To restart Apache (Debian):

service apache2 restart

If you need any further assistance, or if you have any questions, please let us know. We’d love to help!

Was this helpful? Yes No 63% of people found this helpful.
{"message":""}