Basic SSH Commands

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 users 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 users 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.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Checking CPU via SSH

1) Login to SSH 2) Run the command cat /proc/cpuinfo

Checking PHP Version via SSH

1) Login to SSH 2) Run the command php -v

Guaranteed Ram Vs Burst Ram

Guaranteed RAM is RAM that is always available to you and guaranteed. Burstable RAM means that...

How do I enable/disable my Iptables firewall?

To start IP tables on your RedHat server,# service iptables startYou can run the following...

How to upgrade Cpanel

Login to your WHM and follow whm > cPanel/WHM Updates Automatic (STABLE tree) cPanel Package...