Common SSH Commands - Linux Shell Commands

Navigating in Linux/Unix

 pwd  Shows the full path of the current directory
 ls  Lists all the files in the current directory
 ls -al
 Lists all files and information
 ls -alR
 Lists all files and information in all sub directories
 ls -alR | more
 Same as ls -alR, pausing when the screen becomes full
 ls -alR > filename.txt
 Same as ls -alR, outputs the results to a file
 ls *.html
 Lists all files that end with the .html extension
 cd [directory name]
 Changes to a new directory
 cd ..
 Changes to the directory above the current one
 clear  Clears the screen
 vdir  Gives you a more detailed listing than the 'ls' command
 exit  Log off your shell


Moving, Copying and Deleting Files

mv [old filename] [new filename] Move/rename a file
cp [filename] [new filename] Copy a file
rm [filename] Delete a file
rm * Delete all files in the current directory
rm *.html Delete all files in the current directory with the .html extension
rm -rf [directory name] Delete an entire directory, including every file in the directory (be very careful with this command!)
mkdir [directory name] Create a new directory
ls -d */ List all directories within the current directory
cp -r [directory] [new directory] Copy a directory and all files/directories within it

Searching for Files and Directories

find . -name [filename] -print Search for a file starting with the current directory
grep [text] [filename] Search for text within a file
locate [filename] Search for a file in all directories (Requires mlocate to be installed)


File and Directory Permissions

There are three levels of file permissions: read, write and execute. In addition, there are three groups to which you can assign permissions: file owner, user group and everyone. The command chmod followed by three numbers is used to change permissions. The first number is the permission for the owner, the second for the group and the third for everyone. Here are how the levels of permissions translate:

0 = --- No permission
1 = --X Execute only
2 = -W- Write only
3 = -WX Write and execute
4 = R-- Read only
5 = R-X Read and execute
6 = RW- Read and write
7 = RWX Read, write and execute


It's recommended that the group always has a permission of 0. This prevents other users on the server from browsing files via Telnet/SSH/FTP.

Here are the most common file permissions used:

chmod 604 [filename] Minimum permissions for an HTML file
chmod 705 [directory name] Minimum permissions for a directory
chmod 755 [filename] Minimum permissions for scripts and applications
chmod 606 [filename] Permissions for data files used by scripts
chmod 703 [directory name] Write-only permissions for public FTP uploading


How do I unzip/untar a file via SSH?

unzip Unzip a .zip file
tar -xvf filename.tar Untar a .tar file
gzip -d filename.gz Unzip a .gz file

Was this answer helpful?

 Print this Article

Also Read

How do I check my disk space usage?

To check how much space you're using, type the command: # df -h To check how much space a...

Do you support TUN/TAP?

You can enable TUN/TAP support which is required for OpenVPN and others from within your VPS...

How do I add a cronjob?

A cronjob is used to schedule automated tasks such as running a PHP script at a set time. These...

How do I repair all MySQL databases on my server?

If a lot of your databases are having problems you can repair them with the following commands...

How do I add users to my VPS?

We do not recommend using root access for everything which is why you should always create...