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 user@domain.com /var/log/exim_mainlog
Searches the file exim_mainlog for all instances of the e-mail address user@domain.com.
wget – Retrieve files from remote locations.
wget http://domain.com/file.tar.gz
Pulls the file ‘file.tar.gz’ from the domain ‘domain.com’
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.
Related Articles:

About the Author: Jay Allen
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Edit the PHP Memory for Your WordPress Site via WP Toolkit
Read ArticleWhat is CGI-Bin and What Does it Do?
Read ArticleTop 10 Password Security Standards
Read ArticleTop 10 Password Security Standards
Read ArticleHow to Use the WP Toolkit to Secure and Update WordPress
Read Article