Start Using Linux - Basic Terminal Commands

This is a compilation of some terminal commands I've found useful.

Before starting, I'd like to emphasize on a few things:
- You might want to understand the filesystem hierarchy in linux before you start.
- When you start terminal, your default working directory is /home/user-name
- If you want to get more info on any command, just type '
command-name --help' without the quotes in terminal.
- In this post, when I say 'type' something in terminal, it means 'execute it' by typing it and pressing enter.
- Whenever you want to end a looping command, for example, ping in terminal - press Ctrl + C.

These are the list of commands explained in this post:

cat - Used to display contents of a file

pranav@pranav-desktop ~ $ cat Desktop/Hello.ext
Hello, World!
This is a file with a random extension.
pranav@pranav-desktop ~ $

Tip: Try executing the following command
pranav@pranav-desktop ~ $ cat --help

cd - Used to change the working directory

pranav@pranav-desktop ~ $ cd Desktop/
pranav@pranav-desktop ~/Desktop $ cd ..
pranav@pranav-desktop ~ $ cd /
pranav@pranav-desktop / $ cd ~
pranav@pranav-desktop ~ $

Explanation of the above code: Change directory to Desktop (cd Desktop/) -> Go back one level (cd ..) -> Change directory to the root directory (cd /) -> Change directory to the home directory (cd ~)

clear - Used to clear the terminal screen

Basically, what it does is shift everything above the viewable area. Just scroll up to see the history.

pranav@pranav-desktop ~ $ clear

cp - Used to copy files/folders

pranav@pranav-desktop ~/Desktop $ cp [options] source destination
pranav@pranav-desktop ~/Desktop $ cp -dpR twython/ /home/pranav/twython
pranav@pranav-desktop ~/Desktop $

The option -dpR is used to create a replica of the twython folder (located in the /home/pranav/desktop) in /home/pranav.

Here is a small list of options for the cp command:

-a, --archive same as -dpR
-d, --no-dereference preserve links
-f, --force remove existing destinations, never prompt
-i, --interactive prompt before overwrite
-p, --preserve preserve file attributes if possible
-r copy recursively, non-directories as files
-R, --recursive copy directories recursively
-u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing
-v, --verbose explain what is being done

For the full list, run cp --help in terminal.

df - Used to check the free space on your disks

pranav@pranav-desktop ~ $ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 34677256 4375624 28540108 14% /
udev 383740 256 383484 1% /dev
none 383740 524 383216 1% /dev/shm
none 383740 292 383448 1% /var/run
none 383740 0 383740 0% /var/lock
none 383740 0 383740 0% /lib/init/rw
/dev/sda10 80883520 74598944 6284576 93% /media/9465-C776
/dev/sda5 47182872 44720900 2461972 95% /media/Local Disk
/dev/sda6 80895272 59800852 21094420 74% /media/22B86022B85FF2B1
pranav@pranav-desktop ~ $

Tip: Use the -h switch to make it human readable.

exit - Used to exit the terminal

ls (with a lowercase L, not and uppercase i) - Used to list files/folders in the current directory

pranav@pranav-desktop ~ $ ls
bin Documents Music Projects Videos
Desktop hplip-3.9.10 Pictures twython works
pranav@pranav-desktop ~ $

mkdir - Used to create new folders

pranav@pranav-desktop ~/works $ ls
app.yaml index.yaml
pranav@pranav-desktop ~/works $ mkdir py-projects
pranav@pranav-desktop ~/works $ ls
app.yaml index.yaml py-projects
pranav@pranav-desktop ~/works $

mv - Used to move files/folders

pranav@pranav-desktop ~ $ mv hplip-3.9.10/ works/py-projects/
pranav@pranav-desktop ~ $ ls works/py-projects/
pranav@pranav-desktop ~ $

ping - Used to test a network connection

Usage: (To stop the pinging, press Ctrl + C)
pranav@pranav-desktop ~ $ ping
PING ( 56(84) bytes of data.
64 bytes from ( icmp_seq=1 ttl=53 time=121 ms
64 bytes from ( icmp_seq=2 ttl=53 time=121 ms
64 bytes from ( icmp_seq=3 ttl=53 time=121 ms
^C64 bytes from ( icmp_seq=4 ttl=53 time=121 ms
--- ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 121.100/121.298/121.685/0.483 ms

rm - Used to remove/delete files

pranav@pranav-desktop ~/works/py-projects/hplip-3.9.10 $ rm *.*
pranav@pranav-desktop ~/works/py-projects/hplip-3.9.10 $

The above command removes all files with an extension from the working directory, hplip-3.9.10 in this case. Please note that it doesn't delete files without an extension.

To delete everything inside a directory, the option -r can be used.
pranav@pranav-desktop ~/works/py-projects/hplip-3.9.10 $ rm -r *
pranav@pranav-desktop ~/works/py-projects/hplip-3.9.10 $

rmdir - Used to remove empty directories

pranav@pranav-desktop ~/works/py-projects $ rmdir hplip-3.9.10/
pranav@pranav-desktop ~/works/py-projects $

sudo - Used to execute commands as other users

pranav@pranav-desktop ~ $ sudo su pranav
pranav@pranav-desktop ~ $

pranav@pranav-desktop ~ $ sudo su
[sudo] password for pranav:

pranav-desktop pranav#

Here, the user is changed to root.

Note: When no argument is given to the su command, the default argument, root, is used.

tar - Used to do operations like store, list or extract files in an archive.

pranav@pranav-desktop ~/Desktop $ tar -xvzf wordpress-2.8.6.tar.gz
pranav@pranav-desktop ~/Desktop $

For more information on any of the commands or to get the full list of commands, visit bash commands. Alternatively, you can use --help 😉

Have fun with terminal!

Edited on 17 Dec 2009
I came across this post (at today. It contains some really cool tips! Check it out.

Published by


I'm a student pursuing a masters degree in Theoretical Computer Science. Prior to this, I completed my bachelors in Computer Science and Engineering and worked for an year, until I realized that the slogging off at an office in front of the computer is not the job for me. I am easily fascinated and distracted by everything under the sun, which has kept me busy trying to figure out what I am going to. I love dreaming about making radical life decisions, bringing happiness on faces and about a world full of meadows and fluttery creatures and people who do not judge you for what you love doing.

2 thoughts on “Start Using Linux - Basic Terminal Commands”

  1. good job dude . .
    but u could have added commands useful in ubuntu , may be bcoz thats what pepl use the most . something related to apt-get or cool tricks like PS1="AREA 51 command : " which would replace " pranav@pranav-desktop ~/Desktop $ "  .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>