New User Tutorial: Basic Shell Commands

Now that you know how to SSH into your server it is important to familiarize yourself with some basic command line tools.

First you need to log in to your server either as root or as a particular user account if you intend to only modify that user’s files.

Before we proceed any further, a few words on one of the most important commands you can possibly know:

cp – Copy a File

The cp command copies a file from one place to another, or can create a new copy of a file in the same location with a different name.

It is important to note that logging in to a server as root is a powerful but also potentially DANGEROUS system administration tool. The root user is capable of changing/deleting practically everything in a server without any type of warning or confirmation message. Always backup your files before you modify them using a simple backup command:

cp file file.bak

This command will create a copy of “file” in the same directory called “file.bak”.

Now that you can backup files before modifying them it is much, much safer to start learning other commands.

The commands below are some of the most basic shell commands that you need to know in order to manipulate files (moving, copying, renaming, viewing, etc). Please note that each command has several more options available, all of which you can view using the man command.

man – Display Command Manual Files

man cp

Displays the manual file for the cp command.
(When viewing a manual file, type q to quit and return to the command line.)

pwd – Print Working Directory

Displays your location in the directory tree (path).

cd – Change Directories

cd ~

Changes to your user’s home directory.

cd –

Returns you to the previous directory you were working in.

cd ..

Moves you one directory up/back in the directory structure.

ls – List Directory Contents

ls -l

Display directory contents in a “long list” format.

ls -lah

Display all files, including hidden, with a human-readable file size.

cp – Copy a File, More Uses

cp -r /home/user/pics /home/user2/

Recursively (meaning the directory and all of its contents) copy the pics directory from /home/user/ to /home/user2/ .

cp -r -v /home/user/pics /home/user2/

Do the same as the previous command but display a verbose (-v) progress list, showing each file as it is copied.

mv – Move and Rename Files

mv blah.txt /home/user/newdir/

Moves the file called blah.txt to the directory /home/user/newdir/ .

mv blah.txt blahblah.txt

Renames the file blah.txt to blahblah.txt.

chmod – Change Permissions

chmod 755 file.php

Changes the permissions on file.php to 755 (rwxr-xr-x).

chown – Change File Ownership

chown website:website file.php

Changes the file.php so that it is owned by the user and group called website.

rm – Remove a File (Delete)

rm -f oldindex.php

Deletes the file called oldindex.php.

rm -rf olddirectory/

Deletes the directory/folder called olddirectory.

cat – Display File Contents

cat index.php

Displays the entire contents of the file index.php.

grep – Search Files or Output

grep /var/log/exim_mainlog

Searches the file exim_mainlog for all instances of the e-mail address

wget – Retrieve files from remote locations.


Pulls the file ‘file.tar.gz’ from the domain ‘’

tail – Display End of a File

tail -n 50 /var/log/exim_mainlog

Displays the last 50 lines of the file exim_mainlog.

tail -f /var/log/exim_mainlog

Persistently watches the file exim_mainlog as the server makes changes to it (real-time).

w – List Active System Users

Displays a list of users who are logged in to the system through a remote shell or local terminal, what they are doing, and other relevant information.

Liquid Web’s Heroic Support is always available to assist customers with this or any other issue. If you need our assistance please contact us:
Toll Free 1.800.580.4985
International 517.322.0434

Be Sociable, Share!
Here's $75, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support.