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 – view contents of a file
- cd – change directory
- clear – clear the terminal windows
- cp – copy
- df – view free space in disks
- exit – exit terminal
- ls – list contents of current folder
- mkdir – create a new folder
- mv – move
- ping – ping a remote server
- rm – remove files/folders
- rmdir – remove empty folders
- sudo – access as another user
- tar – operations with compressed archives
cat – Used to display contents of a file
Usage:
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
Usage:
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.
Usage:
pranav@pranav-desktop ~ $ clear
cp – Used to copy files/folders
Usage:
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
Usage:
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
Usage:
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
Usage:
pranav@pranav-desktop ~/works $ ls
app.yaml index.py index.yaml
pranav@pranav-desktop ~/works $ mkdir py-projects
pranav@pranav-desktop ~/works $ ls
app.yaml index.py index.yaml py-projects
pranav@pranav-desktop ~/works $
mv – Used to move files/folders
Usage:
pranav@pranav-desktop ~ $ mv hplip-3.9.10/ works/py-projects/
pranav@pranav-desktop ~ $ ls works/py-projects/
hplip-3.9.10
pranav@pranav-desktop ~ $
ping – Used to test a network connection
Usage: (To stop the pinging, press Ctrl + C)
pranav@pranav-desktop ~ $ ping google.com
PING google.com (209.85.231.104) 56(84) bytes of data.
64 bytes from maa03s01-in-f104.1e100.net (209.85.231.104): icmp_seq=1 ttl=53 time=121 ms
64 bytes from maa03s01-in-f104.1e100.net (209.85.231.104): icmp_seq=2 ttl=53 time=121 ms
64 bytes from maa03s01-in-f104.1e100.net (209.85.231.104): icmp_seq=3 ttl=53 time=121 ms
^C64 bytes from maa03s01-in-f104.1e100.net (209.85.231.104): icmp_seq=4 ttl=53 time=121 ms
--- google.com 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
Usage:
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
Usage:
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
Usage:
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.
Usage:
pranav@pranav-desktop ~/Desktop $ tar -xvzf wordpress-2.8.6.tar.gz
.
.
.
wordpress/wp-content/themes/default/archives.php
wordpress/wp-content/themes/default/search.php
wordpress/wp-content/themes/default/screenshot.png
wordpress/wp-content/themes/default/archive.php
wordpress/wp-content/themes/default/comments-popup.php
wordpress/wp-content/themes/default/footer.php
wordpress/wp-content/themes/default/page.php
wordpress/wp-content/themes/default/sidebar.php
wordpress/wp-content/themes/default/style.css
wordpress/wp-content/themes/default/functions.php
wordpress/wp-content/themes/default/links.php
wordpress/wp-content/themes/default/rtl.css
wordpress/wp-cron.php
wordpress/wp-load.php
wordpress/wp-feed.php
wordpress/wp-mail.php
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 lindesk.com) today. It contains some really cool tips! Check it out.


2 Comments on “Start Using Linux – Basic Terminal Commands”
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 $ ” .