• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

[References] Master Linux Command Reference

Not open for further replies.

Satissh S

Master Linux Command Reference

Ok, You've installed linux, Gr8! Here is a free cookie.
But learning and using linux will be meaningfull with the knowledge of the following ESSENTIAL *nix commands and their PRACTICAL applications.IMHO Here are a few commands which we'll be using typically for routine work as well as system administration of linux. Of course this guide is meant to be no where near comprehensive that's why i request our friends to add new commands which they think will be ESSENTIAL and USEFUL. Thanks a lot!


Addendum 1: bash cheatsheet
Here are a few nifty stuff you can use with the following commands,
| =====> Pipe stuff out
&& =====> Combine commands
\ =====> Use next line to start a added command interpreter without executing the previous command
>> =====> Save output to a file by appending it
> =====> Save output to a file by deleting its contents
< =====> Direct contents of a file to a command
ctrl+c =====> Finish the running command
ctrl+l =====> Clear screen
fg =====> to bring a suspended process to foreground
bg =====> to make a process to go to background.
-v =====> print verbose output
& =====> Executes the current command in the background and gives u access to the terminal.. eg: gimp&

Addendum 2: copypasting within terminal
If working on root terminal, you need to have gpm enabled to select stuff with the mouse and use the middle mouse button to paste them. If workin on a terminal emulator,
Select stuff with mouse and then,
[shift] + [delete] ==> copies stuff
[shift] + [insert] ==> paste stuff
All these are extremely useful for posting outputs of the command in online support forums.

Now to the command reference,
1 . Mount :
Mount command is used to mount a filesystem. To mount a FS we use the mount command followed by mount point or device file name as shown here,
the syntax is,
# mount something somewhere

mount /mnt/cdrom
This commands mounts the device with a pre-defined mount point of /mnt/cdrom in FSTAB(/etc/fstab) which is the cdrom drive /dev/hdc or /dev/cdroms/cdrom0 which is a symlink to /dev/hdc by the way.

mount /dev/hdc /mnt/cdrom
This command mounts the device /dev/hdc in /mnt/cdrom. The device needs to be specified if it's not pre-defined in FSTAB.

Popular Parametres:-
a. -t
One of the most important param to mount command is -t which specifies the filesystem type,
For example, if one wants to mount a ntfs FS
mount -t ntfs /dev/hda1 /mnt/win_c
This command mount the ntfs partition /dev/hda1 in /mnt/win_c
You can specify different FS's such as reiserfs, fat32 etc along with -t . Msdos formatted floppies use 'msdos' filesystem. if you are unsure abt the partition use '-t auto' to try making the shell guess the mount point.

b. -r
The -r param helps you to mount stuff in a read-only filesystem or mount stuff as readonly.

c. -w
The -w param helps to mount the filesystem with write option. Special case for us is that knoppix livecd usually mounts the hdd's partitions as readonly as default. You use this option to mount partitons using write permission just in case you need to trouble shoot a boot loader config.

d. -o loop
The -o loop option parametre is used to mount ISO disk images to another directory and view the contents of the ISO.
For example you want to view the contents of a D/L'ed ISO
mount ubuntu-breezy-5.10-i386.iso /mnt/image -o loop

2. Umount :
The umount command helps to unmount filesystems. You can invoke this with,
umount /dev/hda2 (device name) or 
umount /mnt/win_c (directory mounted)

Popular Parametres:-
a. -f
This -f parametre forcefully umounts a network filesystem or an unreachable filesystem.

b. -l
Force unmount the filesystem. We especially use this command when we come out of a chrooted partition and wan't to unmount that filesystem,(IME usual problem with knoppix) it would be busy. We can use lsof command to check which programs are accesing the filesystem and unmount it.

3. fdformat :
This command performs a low-level floppy disk format
fdformat /dev/fd0

4. mkfs :
Using the mkfs command you can create any supported filesystem on an accesible diskvolume. This is high-level formatting and data lost is lost forever.
For example, if we wan't to create a windows boot floppy quickly, all you have to do is
mkdosfs /dev/fd0
This command is also used to create filesystems on large partitions
mkreiserfs /dev/hda3
mke2fs -j /dev/hda3
mkswap /dev/hda3
mke2fs /dev/hda3
mkjfs /dev/hda3
where /dev/hda3 being the targeted partition. There is another way to do the above however,
mkfs -t reiserfs /dev/hda3
does the same job as well.

5. cp :
As the name suggests, copies files from here to there.
cp $LINUX/i386/boot/bzimage /boot/bzimage
copies the file bzimage from one folder to another.

Popular parametres:-
a. -a
The -a parametre is used to archive a directory to another location, maybe as a backup also i saves file permissions and symbolic links status. Used for backing up file WITH permissions, so that you can replace if something gets screwed up.

b. -b
Ths -b param instructs the cp to make backup of any file with the same name in the destination directory as the copyied file so that the command doesn't explicitly ask you to what to do.

c. -f
This param instructs the command to forcefully replace any exixting file with the same name as the copyied file.

d. -r
Copies files and folders again and again recursively.

e. -i
Asks for confirmation b4 replacing any existing file.

6. mv :
As the name suggests moves files from here to there and as the name doesn't suggest it also renames files.
mv /home/user/file1 /home/user/files/file1 <moves file1 >
mv /home/user/file1 /home/user/file2 <renames file1 to file2>

The parametres for cp also apply to mv.

7. rm :
This command coressponds to delete
rm /home/user/garbage1 <where garbage1 is the deleted file>
for directories however,
rm -R /home/luser <where /home/luser is the deleted directory>
A similar command is rmdir
Always re-check a rm command because a file rm'ed is pretty much deleted. The params of cp and mv also applies to rm.

8. ln :
There are two types of links, hardlinks and symbolic links. Hardlinks refer to link for the same file with two or more directory entry. That is say a file called file1 resides at /home/user and we create a link for this file1 to /home/user/files/file1 then the file resides on both and is deleted only when both the references are deleted. Symbolic links are softlinks that refer to the file, like a pointer from another location. We can use ln or cp command to create hard as well as symbolic links. We use
cp -l to create hard links and cp -s to create symbolic links. However my favourite method is ln.
ln /home/user/file1 /home/user/files/file1 <hard link>
ln -s /home/user/file1 /home/user/files/link1 <symbolic link>
If you get hold of software binaries, you can simply copy the directory to a conventional location, say for azureus to /opt and create a symlink pointing to /usr/bin so that you need not cd into the azureus directory and start it with ./azureus.
ln -s /opt/azureus/azureus /usr/bin/azureus
Now you can type azureus in run dialog to run azureus.

9. ls :
Using ls to view the file contents is one of the fun parts of linux, practically when ls is combined with switches and sequences you don't even need a graphical file manager.
The following ls command is used to view the contents of the folder with permissions.
ls -l
use ls with ordinarily to view the folder contents is quite efficien for small folders but when you want to view the particular files starting with x we add the following sequence.
ls /etc/X11/x*
this command will list all the files in /etc/X11/ directory starting with 'x'.
Using [tab] autocompletion along with these neat tricks makes bash one of the most favourite shells for users.

10 cd :
Change into a directory from another directory.
cd /usr/local
changes the current working directory to /usr/local.
you can use pwd to view the current working directory.

11 mkdir :
Create a new directory within the current directory or another directory anywhere else.
mkdir shared (make a directory shared within the current /usr/local directory)
mkdir /usr/local/bin (make a directory bin within /usr/local)

12 chmod :
Change the permissions to files or directories.
To check permissions of a 'new' directory you can use the following command
ls -ld new
drwxr-xr-x <owner> <group> <modified time>
this specifies the permissions as
{file-type} {owner} {group} {others}
<directory><read-write-execute> <read-xxx-execute> <read-xxx-execute>
to change em'
chmod 700 new
Permissions cheat sheet:
777 =======> rwxrwxrwx
755 =======> rwxr-xr-x
700 =======> rwx------
644 =======> rw-r--r--
000 =======> ---------
changes the permissions to rwx------ meaning no access to group as well as others and full access to the owner.
There are several numbers denoting file permissions as modes. The popular is 700 which gives full access to the owner.
Popular Parametres:
A most used parametre is -r to recursively change permissions to direcotries and files within them. for example,
chmod 700 -r new
changes permissions to all files and folders within new to 700

13. chown :
Change the ownership to files or directories
to change the owner for a 'new' file or folder to a new owner.
chown user1 new
changes the ownership of new to user1.
Normally we use the this command recursively with -r option to change recursively the ownership of directories.
chown -r user1 new
A similar command is chgrp which changes the group similarly.

14. df -h :
The df command is used to view info abt all mounted partitions.
Use df -h to find the used and free space of your hard disk volumes.
df -h
It will display as output, like for example
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda4             7.1G  4.5G  2.6G  64% /
udev                  505M  168K  505M   1% /dev
/dev/hda1              21G   18G  2.5G  88% /home
/dev/hda2             9.9G  2.3G  7.1G  25% /backup
/dev/hda3             266M   16M  237M   7% /boot
none                  505M     0  505M   0% /dev/shm

15. pciutils :
Pciutils are a set of utils to make the life of a *Nix system admin easier
1. lspci:
View your pci devices. This displays all the devices connected via pci. Normally we either use grep to search the output and display the ones we want.
For example,
lspci | grep VGA <outputs your VGA device>
01:00.0 VGA compatible controller: nVidia Corporation NV40 [GeForce 6800 GT] (rev a1)

lspci | grep audio <outputs your audio device>
00:1f.5 Multimedia audio controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) AC'97 Audio Controller (rev 02)

Or, you can pipe the entire thing view it using more or less, or you can save it as a log and view using your editor.
lspci | more
lspci >> log

2. lsmod :
Displays the loaded modules,
Module                  Size  Used by
snd_intel8x0           30944  0
snd_ac97_codec         91900  1 snd_intel8x0
snd_ac97_bus            2944  1 snd_ac97_codec
nvidia               4086128  12
You can pipe them out similarly.

3. lsusb :
Displays the CONNECTED usb devices.
Bus 005 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

4. lsof :
This program displays informations on open files, used devices etc.,
lsof | grep /mnt/cdrom
Use this command to see if a umount fails with device busy quote.

5. dmesg :
Displays the kernel output messages while boot time.
dmesg | less
The same can be used with | or >> to save.

16. du :
The du command displays the disk usage by partition by partition basis. For example,
du /usr <displays how much space each directory in /usr is consuming>
Don't use this command without this --max-depth=n option or you'll find your self having to wait a while ;) This option limits du to n directory depth.
For example,
du --max-depth=1 /opt <outputs>
11283   /opt/xpde
12      /opt/libreadline-java
10432   /opt/eclipse-extensions-3.1
10789   /opt/opera
15397   /opt/RealPlayer
89309   /opt/blackdown-jdk-
5511    /opt/eclipse-extensions-2
10927   /opt/eclipse-extensions-3
21928   /opt/firefox
28961   /opt/thunderbird
20278   /opt/sunbird
1248    /opt/netscape
72972   /opt/sun-jre-bin-
55232   /opt/blackdown-jre-
400     /opt/blackdown-java3d-bin
354677  /opt
Again you can pipe out the output if you can view it in the terminal.

17. stat :
This command displays information about files like ls -ld with permissions, ownership etc.,
But with several other tasty stuff.
stat /opt <outputs>
File: `/opt'
  Size: 568             Blocks: 1          IO Block: 131072 directory
Device: 304h/772d       Inode: 108         Links: 17
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2006-02-12 13:06:18.000000000 +0530
Modify: 2006-02-28 05:03:43.000000000 +0530
Change: 2006-02-28 05:03:43.000000000 +0530

18. uptime :
This command returns the uptime of the system. useful for knowing uptime of servers.
uptime <outputs>
20:50:00 up  2:10,  4 users,  load average: 0.00, 0.00, 0.00

19. free :
This command lists the memory usage of the system.
free <outputs>
            total       used       free     shared    buffers     cached
Mem:       1032792     447436     585356          0      79380     140872
-/+ buffers/cache:     227184     805608
Swap:            0          0          0

20. who and finger :
the commands who and finger provide information abt users logged in to the system.
who <outputs>
sathya   :0           2006-02-28 18:40
sathya   pts/0        2006-02-28 18:40
sathya   pts/1        2006-02-28 18:56
sathya   pts/2        2006-02-28 19:55
finger <outputs>
Login     Name       Tty      Idle  Login Time   Office     Office Phone
sathya              *:0             Feb 28 18:40
sathya               pts/0    2:11  Feb 28 18:40
sathya              *pts/1    1:10  Feb 28 18:56
sathya              *pts/2          Feb 28 19:55
As you can see finger provides some additional information.

21. top :
This is such an essential command which is very hard to ignore. This is more of a utility than a command
top <outputs>
top - 20:56:16 up  2:16,  4 users,  load average: 0.00, 0.00, 0.00
Tasks:  83 total,   1 running,  82 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0% us,  0.0% sy,  0.0% ni, 100.0% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:   1032792k total,   447580k used,   585212k free,    79624k buffers
Swap:        0k total,        0k used,        0k free,   141036k cached
< c o m m a n d l i n e  to execute stuff within top ----------------->
 5616 root      16   0 60820  49m 3844 S    0  4.9   1:31.47 X
    1 root      16   0  1460  516  448 S    0  0.0   0:00.69 init
    2 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/0
    3 root      34  19     0    0    0 S    0  0.0   0:00.00 ksoftirqd/0
    4 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/1
    5 root      34  19     0    0    0 S    0  0.0   0:00.00 ksoftirqd/1
    6 root      10  -5     0    0    0 S    0  0.0   0:00.09 events/0
    7 root      10  -5     0    0    0 S    0  0.0   0:00.00 events/1
    8 root      10  -5     0    0    0 S    0  0.0   0:00.00 khelper
    9 root      11  -5     0    0    0 S    0  0.0   0:00.00 kthread
   12 root      10  -5     0    0    0 S    0  0.0   0:00.00 kacpid
   86 root      10  -5     0    0    0 S    0  0.0   0:00.01 kblockd/0
   87 root      10  -5     0    0    0 S    0  0.0   0:00.00 kblockd/1
   90 root      10  -5     0    0    0 S    0  0.0   0:00.00 khubd
  182 root      20   0     0    0    0 S    0  0.0   0:00.00 pdflush
  183 root      15   0     0    0    0 S    0  0.0   0:00.04 pdflush
Notice the command line, there we execute severel commands for working with processes.
As you can see x consumes a lot of memory and is displayed in the top.
Top Cheat sheet:
r --> change the nice value for processes
k --> kill a process with process ID
N --> sorts by PID number
M --> sorts by memory usage
T --> Cpu time used.
m --> toggles display of system memory info.
h --> help with top
q --> quit top.

22. Process manipulation :
ps and pstree commands are used to deal with processes. ps outputs processes info and pstree outputs tree like info structure.

1. ps
ps <outputs>
 PID TTY          TIME CMD
 6030 pts/2    00:00:00 su
 6033 pts/2    00:00:00 bash
 6156 pts/2    00:00:00 ps

2. pstree
pstree <outputs>
as you can see pstree displays the initiated process with the root process, all providing us tasty info.

3. nice and renice
nice and renice commands are used to start a process and set process with different priorities.
nice <option> <command>
renice -2 -p [i]nnnnn[/i]
the above command changes the priority of process with ID nnnnn to -2. giving it precedence over others.

4. kill
This kill command is used to kill a process with a -s signal and process id.
kill -l (use this to display the list of signals)
kill -s [i]signal[/i] pid[...]

23. grep :
Search and limit output using grep
The grep command is used to search and limit the output, like we did when using lspci utilities.
For example, if you want to view screen information for your screens in XORG.Conf(/etc/X11/xorg.conf)
more /etc/X11/xorg.conf | grep Screen <outputs>
Screen      0  "Screen0" 0 0
Section "Screen"
        Identifier "Screen0"

24. slocate :
Use this security enhanced version of locate to get files and folders info.
First you need to create a directory index
slocate -u
This wud take sometime to finish.
then search for files
For example,
slocate xorg.conf <outputs >

25. echo :
The command echo is used to print stuff in the standard output.
for example,
echo hello world <outputs>
hello world
However, its most useful use is you can redirect it to file.
for example,
echo \
> GENTOO_MIRRORS="http://mirror.phy.olemiss.edu/mirror/gentoo"\
> >> /etc/make.conf
The above commands add the line GENTOO_MIRRORS="http://mirror.phy.olemiss.edu/mirror/gentoo" to /etc/make.conf.
But watchout though! i ended up totally cleaning my /etc/make.conf by using >param which deletes the contents of the file and adds the echoed stuff. So always make sure you use >> .

So that ends things up., but let this thread be used by all of us to add the commands that we think will be useful for a new linux user to learn and implement. Lets start linuxing, shall we?

Credits :
1. Linus, RMS and friends for creating this awesome OS.
2. All programmers, coders and hackers.
3. Esr and friends of 'OpenSource' movement.
4. All MAN page and document writers of those excelent projects.

License :
This document and its derivatives are licenced under the GNU free document license. (any version)

Request :
To err is human, Please point out any errors, typos in commands in the document, thanks. If you notice any italics tags within code, please notify me. Thanks.

Edit History:
Last edited at 25-6-2006 21:18 pm, edited four times in total.
=> A minor mistake corrected.
=> Altered document in accordance with changing times.
Last edited:

nach p

Nice Thread .Surely help a lot For Newbies like me and also to otheres to venture into GNU/Linux. :) :)
Satissh S

Satissh S

Here are a few more,

26. tar :
This is a very essential command in a way that it compresses and decompresses files. There are a lot of options to this command and it's difficult to list everything here, so i will list the one which most linux users will most probably use and their functions as well as where to use them. For more read man tar This tar command actually calls seperate commands for seperate file type, for example to compress a .tar.bz2 it calls bzip2 command.
Usually, you get the following compressed archive .tar.bz2, .tar.gz, .tgz.
Use the c option to create an archive and x option to extract from an archive.
Options Cheetsheet
c --> Creates Archives
x --> Extracts from archives
f --> Uses the filename after the command for the archive.
j --> Compresses or uncompresses from or to a bzip2 archive. (.tar.bz2)
z --> Compresses or uncompresses from or to a gzip archive. (.tar.gz)
v --> Verbose output.
k --> Does not overwrite file while uncompressing. Use with every command.
t --> Lists files in a archive
r --> Appends files to archive.
p --> Preserve file permissions.
Common Uses
1. To extract a bzip2 file,
tar xkvjpf file.tar.bz2

2. To extract a gz file,
tar kxvzf file.tar.gz

3. To archive files,
tar cvjfp yumbackup.tar.bz2 /var/cache/yum
as you can see, this backs-up all your yum downloads in to bzip2 format which has a better compression than gz.

27. mkisofs :
You dont need k3b to burn cd's in linux. For command line junkies, here is how you can burn using commandline. The mkisofs command creates an iso file that you can burn using cdrecord. This command has a lot of options, but i'll list only the main ones here. So you can use man mkisofs to learn more.
Basic usage for creating an iso is,
mkisofs -r -J -T -o /backup/backup.iso /home
as you can see this command creates a backup.iso in the current directory which creates a backup of /home.
Options Cheatsheet
-r --> Preserves rockridge extensions which makes the cd readable in unix based systems.
-J --> Preserves Joliet filesystems which makes the cd readable in M$ Windblows.
-T --> Preserves long filenames.
-o --> Prints OutPut.

28. cdrecord :
This command is used to burn the cd we created using mkisofs. As with any linux app, this has a lot of options but i'll be reviewing only the most useful ones here.
cdrecord -v -tao speed=40 dev=/dev/hdx /backup/backup.iso
as you can see, this command burns the backup.iso we created to the empty cd in /dev/hdx with the following options.
cdrecord cheetsheet
-tao --> use track-at-once mode. You can also use -dao (disk-at-once) mode if you want.
-v --> Prints output
speed --> Sets the recording speed. Note that there is no 'x' at the end, only number.
dev= --> Sets your device. You can either use symlinks as /dev/cdrom or specify your device directly such as /dev/hdc
You can also use -multi to enable multisession mode. This needs to be used for all subsequent sessions.

PS: I request the friends here in the digit opensource community to continue in the command number so that we can use the command number as a reference when giving to new users. Thanks :)

Edit History :
Corrected a minor mistake. ;)


Wise Old Owl
Here .. the du command can also be used with the -s option to just get the total size of a directory without displaying the size of each file..

du -s ./

ways to get to your home directory


cd ~ 
cd /home/user

cd $HOME


. points to current directory

.. previous directory

Info about yourself...

id to see your username,group(primary and secondary)

echo $USER to print your username


The groups you belong to..

set list all the variables that can be set in the shell and enviroment

env to see environment variables only

you can set them just type the variable name= new value

Personalize your system....

/etc/issue Message at login prompt

/etc/motd Message of the day, message that will be displayed after you login

alias set an alias to a command that you find easy to remember...

alias c='clear'
alias bye='logout'

add your aliases to your. .bashrc file so they are permanent.

to unset an alias for the current session use the unalias option.

change your prompt...

PS1='[\u in \w]' add this also to .bashrc if you want to be permanent

cheat codes

/u username
/t time
/w working dir
/W full path
/h hostname


The tar command can be also like this without so many parameters

tar cvf file.tar file Create a tar

tar jcvf file.tar file Create a tar and compress it with bzip2

tar zcvf file.tar file Create a tar and compress it with gzip

tar xvf file.tar To extract

with bzip2 tar xjvf file.tar.bz2

with gzip tar zxvf file.tar.gz

I am a vi fan ...so will compile a list of shortcuts and then paste it...Since I am on dialup I can`t type it all now... :D
Satissh S

Satissh S

A few more :)

29. Chroot :
The chroot command, 'change root' changes your root directory to the directory specified. For a temporary sesion, you can type exit to come out of it. We usually do this to repair a broken install or repair some mal-functioning in the system.

chroot /xxx/xxx /bin/bash
where, the /xxx/xxx is the directory you want to make your temporary root directory.

Chrooting the world:
To chroot to your system, from within a live-cd,
1. Mount all the partitions.
2. Enable swap if you have one.
3. Mount the proc filesystem after mounting the root, this is important!!
mount -t proc none $PATH/proc
where $PATH is the path to where root partition is mounted.
4. Now execute,
chroot $PATH /bin/bash

30. Rmdir:

The rmdir is a command to delete a directory, similar to rm command but it deletes the directory only. So if you try to delete a directory with rmdir that has files you'll get an error that the opeartion can't be performed. So rm -r is more effective.

rmdir $HOME/unlucky
will delete the directory unlucky in your home directory.
Last edited:


Wise Old Owl
Great Job Satish. I think you can add a few more there to make it a one stop
reference. Including Copying, moving files ( using Terminal Window), chown,
Some administration commands, the basic commands etc., That will help the
users migrating from Windows to Linux.
Satissh S

Satissh S

Well, i've added those in the first post, command number 5,6,8,12,13 :)
We'd love if this was a wiki wont we?? , we can edit easily, make up for navigation. etc.,
Not open for further replies.
Top Bottom