Skip to main content

A Newbies guide to Linux Console

Newbies guide to Linux Console

Over the years there has been tremendous growth in Desktop Linux , and Linux distributions these days are getting more and more user friendly with all kind of fancy graphical interface . Still the power of Linux or any other UNIX distribution lies in it console and shell commands . Now even though shell is often considered difficult by Linux newbies still it's possible to learn few basic commands , and in this article I try to explain basic commonly used console commands .

The general format of Linux command line :

$ command -options target

Where target is target filename or expression

Some Commonly used Linux commands : -

Showing Currently working directory

The command prints the current working directory , for example

$ pwd

It shows /home/ambuj because /home/ambuj is the currently working directory .

Listing files in the directory : -

ls -a :- Displays all the files in the directory , by default ls does not show hidden files( hidden files start with (.) )

ls -l :- Displays the detailed listing of the files in the directory , information like Permission , links , owner , group , size , date , name are displayed

ls -S : the -S option displays the file list in a sorted fashion with the biggest sized file displayed first

ls -sS : the -s option displays file size before the filename combined with -S option it displays a sorted list of files currently in directory with the filesize infront of the filename.

ls -Sr : the -r option combined with -S displays the sorted list of files in the current directory with the smallest sized file displayed first.

ls -sSh : the command displays the sorted list of files in the directory with the file size displayed in a more understandable fashion.

ls -F : this command displays the list of files and directory with directories ending with (/) , executable files with (*) , Symbolic links with ( @)

Removing Directories/File : -

rm directory_name/File_name : Removes directory , Files

rm – i filename/directory_name : Removes directory/file with confirmation

rm -rf filename/directory_name : Removes directory and sub-directory recursively , -f stands for Force

rm -r Directory_Name : Removes directory if it is empty

Copying completely one directory to another directory

cp -r source_directory_name destination_directory_name

-r stands for Recursively

Creating Archives :

gzip (GNU Zip)

gzip can be used for compressing a single file , it is not meant for compressing entire directories as other file formats do . The default extension used bu gzip archives is (.gz) .

gzip filename.ext would create a file name filename.gz and replace the existing filename.ext file with filename.ext.gz file which is compressed gzip archive , the gzip command retains the file's attributes the modification,time stamp, access etc.

The compression level of the file can be varied by using options from 1 to 9 while compressing a file

gzip -1 filename.ext would compress the file quicker but with less compression.

gzip -9 filename.ext would compress the file slower but with more compression.

the default compression level is 6.

The filesize of compressed gzip archive would depend on the orignal file format it would do well with a non - archived file such as txt,doc,bmp etc but would fair poorly with JPG , PNG etc which are already compressed by some algorithm.

The gzipped file can be decompressed by using the gzip -d or gunzip command at the command line.

the default file extension used by gzip archives is .gz if you want to use a different file extension it could be done by using the -S option
example : gzip -S .x filename.ext would create a archive by the name of filename.ext.x

tar ( Tape archiver )
The tar program combines a number of files and directory in a single file which then can be compressed using a gzip or bzip2 program to reduce it's file size.

tar -cvf file.tar file1 file2 file3 file4 : This would create a tar archive combining the file1 file2 and file3 into a single file the archive have the same name as the file1 since we have specified the -f option which makes tar use the first option as the filename of the archive , -c tells the tar program to create a archive and -v option displays all the background information on the screen.

tar -cvf file.tar file1.tar file/ : This command would create a archive named file.tar with file1.tar and file subdirectory as the content of the archive .

tar -cvzf file.tar.gz file1 file2 file3 file/ : This command would create a tar file consisiting of the files and directory specified and then the file is compressed using the gzip program, to create a final archive file.tar.gz.

tar -cvjf file.tar.bz2 file1 file2 file3 file/ : This command would create a tar file consisiting of the files and directory specified and then the file is compressed using the bzip2 program, to create a final archive file.tar.bz2

tar -xvf file.tar : This command would extract all the files contained in the tar file file.tar

tar -xvjf file.tar.bz2 : This command would extract all the files contained in the file file.tar.bz2 , it would first call the bzip2 program to extract the file.tar and the call tar to extract the file.tar and it's conetent.

tar -xvzf file.tar.gz : This command would extract all the files contained in the file.tar.gz , it would first call the gzip program to extract the file.tar and then call tar to extract file.tar and it's content.

If you have created the file.tar but want to add some file(s) later it can be done using the following command and using the -rf option .
tar -rf file.tar file(s)

The bzip2 is similar to gzip program but compresses file better and more effectively as compared to gzip program . The default extension used by bzip2 program is (.bz2) , the usage of bzip2 is very similar to the gzip program but has some additional options , which are described here .

bzip2 -k filename.ext : This commmand would create a archive of the filename.ext but would also keep a copy of the orignal file unlike gzip which replaces existing file with the the new archive file.
the bzip2 program also has different compression level ranging from 1 -least to 9-maximum . which can be set by using syntax like : bzip2 -1 filename.ext

bzip2 archives can be extracted by using the bzip2 -d option or by using the program bunzip2 .

Displaying file in the console

$ cat file-name(s)

The above command displays the content of file one after the another .

cat v1 v2 v3 > v4 This statement would combine the content of textfile v1,v2,v3 and create a new file v4 having all the content of three files.

cat v4 >> v5 This statement would append v4 file at the end of file v5. To end the statement type (Ctrl + D (EOF))

cat > filename << STOP This statement would create a filenamed filename at the console and accept input from the user for the file , the file is ended(terminated ) on pressing Ctrl + D.

$ more file-name

The above command displays the content of file page-wise , asking user to press a key usually “space bar” when the entire screen is filled to move on to next screen. The command is particularly useful for long files.

$ head File-Name

The above command displays the first few lines of the file .

$ tail file-name

The above command displays the last few lines of the file .

$ wc file-name

The above command would count the lines , words and characters of the file .

Creating Soft-Link/File -Aliases

If you are right now in /home/xyz directory and you issue the following command , it would create a soft-link of the file( file-name ) in the directory /home/xyz

$ ln -s /path/file-name

Searching Commands

$ grep -r “Text” *

The above command would display all the files in the current directory and all it's sub-directory having “Text” by searching recursively .

$ grep -n “Text” filename

The above command search for “Text” in the file-name and displays the line-number where the text was found .

$ grep “file[- ] name “ file

The above command searches for text “file-name” and “file name” in the file and displays it on the screen .

$ find file-name

the above command searches for file-name in directory hierarchy .

Some Other Miscellaneous Commands

$ cal
Commands displays calendar on the screen

$ clear
The command clears the console screen of any text

$ man command
Gives information about command

$ passwd
Above command allows changing of password of logged in user

$ df
Above command displays the free diskspace .

$ who
The command shows the user who are logged into the system .

$ env
Shows environment variables

$ ps
Shows running processes

$ top

The above command shows a dynamic real-time view of running system . It displays system summary information as well as list of task being managed by the linux kernel .

Article Written by : Ambuj Varshney (
For Desktop on Linux Blog ,
(C) 2007 , Ambuj Varshney


  1. Anonymous4:34 AM

    hey, thanks... very useful for newbies like me :)


Post a Comment

Popular posts from this blog

Over 16 Small Games For Ubuntu Linux

Over 16 Small Games For Ubuntu Linux

Ubuntu Linux is one of the most popular Linux distribution , it is especially popular among Linux newbies and windows refuges . Now Ubuntu Linux does come with a descent set of applications , still there is a scope for including some more quality applications and especially games . Now in this tutorial i will show you how to install a large number of small , easy and less resource hungry games on Ubuntu Linux with screen-shots of games .

1. Rocks 'n' Diamonds

Rocks 'n' Diamonds is a Boulderd*sh game for X11 with more than just the falling rocks and diamonds of its namesake. The object is still to collect all the diamonds (and emeralds), then get to the exit before time runs out. But your character must make use of bombs, spaceships, and many other elements in order to fill his quota of jewels.

Installation : -

Type the following command in the terminal window


13 Things to do immediately after installing Ubuntu

In this article i describe some of the things to do immediately after installing ubuntu on your machine . Since most of the people reading this would be shifting from Windows to Linux with a system dual booting so i would focus more on making transition easy from Windows to Linux.

Creating Your ultimate Ubuntu 7.10 Desktop

Ubuntu 7.10 Codenamed Gusty Gibbon was released few weeks back with much fanfare ,now Ubuntu for past couple of years has been one of the most popular Desktop Linux distributions . Ubuntu 7.10 includes a number of features , applets and Wizards to simplify desktop Linux experience however because of many licensing restrictions it does not include out of the box support for popular audio/video codecs and many commercial but good applications . Also because of the limitation of trying to accommodate all kind of applications on single CD Ubuntu comes with a limited set of applications .

Now , i often have arguments with my friends who are new to computers that windows is…

Convert text files to MP3 under Linux

Even though I am not a fan of audio books and the only thing I use my iPod for is listening music still while exploring Festival(which is basically a General multi-lingual speech synthesis system) I found out that it's very easy to convert normal text files into mp3 using festival . Now this could be especially useful for people who either listen to audio books or people who have difficulty in reading.

First we would need to install festival. We can install festival with the following command :

sudo apt-get install festival

Now we need to install voices which would be used to dictate the text (install any one of the following ) :

To install British Accented male voice issue the following command :

sudo apt-get install festvox-rablpc16k

To install American Accented male voice issue the following command:

sudo apt-get install festival festvox-kallpc16k

Now once you have installed festival and voice package we are ready to convert text files .wav files .

Lets say you want computer to rea…