Archive for June, 2011


Types Of Shells


Shells plays an important role in Linux and Unix system. Everything that is happening on your distro is either because of the shell or the kernel. Moreover, a backend  shell is initialized as soon as you made a login . There are lots of shells in the Unix and Linux system. Let’s try to know more about them :

What is a shell ?

Shell is the software installed on your system that works as command-line interpreter i.e. it takes the commands you type, interpret them and gives them to operating system (kernel) through system calls to execute. There are many different shells available to choose from in Linux.

C Shell : C shell was created by Bill Joy, while he was studying at University of California, Berkeley. He released it under BSD license, the syntax of C shell is similar to C programming language hence the name C shell.

TC Shell: An improved version of C shell, provides some additional features like command line completion and editing. In most of Linux systems /bin/csh is linked to /bin/tcsh and it alternatives, so when you try to start the C shell, TC shell gets started.

C shell linked to its alternatives

Korn Shell (ksh): Korn shell was developed by David Korn at AT&T Bell Laboratories. It contains may features of C shell and Bourne shell.

Bourne Shell(sh): The default shell in many Unix systems developed by Stephen Bourne of AT&T Bell Laboratories.

GNU Bourne-Again Shell (bash): Bash shell is default shell in most of Linux distributions. Its a free and open source clone of bourne shell. It was developed by Brian Fox for the GNU project. Its the most feature rich shell available and is compatible with bourne shell.

To find out all the shells installed on your system type “$cat /etc/shells”. Your default shell is defined /etc/passwd file.

My Default Shell

To switch to a different shell on your system just type the name of that shell (as in /etc/shells) and hit enter.

Z Shell(zsh):  Sorry I forgot to write about this shell (Don’t Know How :( ). Thanks to all of you for reminding me. Well The Z shell (zsh) is a Unix shell that can be used as an interactive login shell and as a powerful command interpreter for shell scripting. Zsh can be thought of as an extended Bourne shell with a large number of improvements, including some features of bash, ksh, and tcsh. It includes features like automated spell correction, editing  multiple line command within a single buffer and many more.

In the next part of the article we will learn about “How bash shell interprets a command”. So Google about the shells more and more. If want to become a Linux administrator, then you must  have  a good control over the shells.

About Author : This post is written by Sumit Rai. He is second in command of this blog. Sumit loves to play with grub and spends most of his time in manipulating the hardware through shell.  He is trying his hands on assembly languages also. You can contact him at sumitrai96@gmail.com .

Pages : Follow ankurtwi on Twitter      


This is a part of my article which got published in the International Magazine “Linux For You” also popularly know as LFY. The article was published  under the name of “Let’s Play With Emacs  CLI”  in the August 2010 edition. All the work done is under the creative common license as specified in the widgets also :)

Text Editors are very important tool for everyone, especially for the programmers. So let’s play with them :D   I am going to discuss the basics of Emacs text editor in this post.

Emacs was developed by Richard Stallman under the GNU project and he released his Emacs source code under a similar free copyleft software license called the EMACS Public License. C and Emacs Lisp  are the programming languages behind this editor. This editor is also known as “The King Of Editors”. Believe me, the title matches exactly with its unique features. The Emacs environment doesn’t seem intuitive at first glance and it doesn’t work like other editors and word processors but learning Emacs is very easy. The latest version of Emacs is 23.2 . It comes pre installed in most of the distributions. You can install it by typing “sudo apt-get install emacs ” (without quotes) on debian distribution. To install it manually download it from http://ftp.gnu.org/gnu/emacs/ . You can check your version by typing “emacs –version”  in the terminal. Emacs is a cross platform text editor and I have tried it on windows as well. Emcas was designed by keeping in mind that users don’t have to waste their time in clicking mouse buttons (start using Emacs and you will feel the same).

Emacs has two modes – GUI and CLI . Type “emacs” in the terminal to get the graphical mode. Below is the snapshot of the graphical mode :

GUI Mode Of Emacs

Graphical mode can be useful if you are not much familiar with the command line of GNU/Linux. Our main focus in this article is on the CLI mode. You can start the CLI mode by typing “emacs -nw” in the terminal. You should get something like this :

Welcome to CLI mode of Emacs

Start a new file in Emacs by typing “emacs -nw filename”  in the terminal and you should see a blank buffer. Emacs works on buffer system. Any thing you write will be there on your buffer. When you save the buffer, it gets permanently written on your disk. Default buffer in it is known as SCRATCH BUFFER. New file buffer should look something like the screenshot shown below :

New File

At the top is the menu bar like in the GUI interfaces but you hardly use it in the CLI. Below that is your buffer area where you can write your contents and data. Mode line is below the buffer. You can call it as the status bar of the editor. It gives you important information about your Emacs session and about the current buffer displayed in the window above it, including whether your latest changes were saved to disk or not , on what line number the cursor is at, how far into the buffer the bottom of the screen is (in percentage of the whole) and the current active features and settings of Emacs. Mini Buffer is below the modeline where Emacs displays the message relevant to any operations.
You don’t need to use the mouse in Emacs as there are many key bindings (combination of keys) in this editor. Key bindings starts with two most important and common key that are Ctrl and Meta keys. Meta key in case is Alt key or Esc key. I have already told you how to start the Emacs and now going to tell how to exit it because it doesn’t have a normal exit. To exit the Emacs, key combination used is Ctrl-x Ctrl-c. It means press Ctrl key then press x while still holding the Ctrl key and then press c while holding the Ctrl key. It exits the Emacs command line and you will again be in the terminal. In the mini buffer you will see the progress of your command while you are typing it. I am listing some important commands below that will help you to start your work initially  on  Emacs :

Key Combination          Function
C-x C-s                   Saves the content in the buffer
C-x C-f                    Find a file, Start a file by giving location
C-x k                       Kill buffer
C-x b                       Switch between multiple buffer
C-p                          Move the cursor to previous line
C-n                          Move the cursor to the next line
C-f                          Move the cursor one letter forward
C-b                          Move the cursor one letter backward
M-f                         Move the cursor one word forward
M-b                         Move the cursor one word backward
C-a                          Move to beginning of line
C-e                          Move to end of line
M-a                         Move to beginning of sentence
M-e                         Move to end of sentence
C-_                          Undo the change

C = Ctrl, M = Meta (Alt or Esc)
I hope this will be enough for you to start with the emacs. Believe me guys, it’s worth giving a try! In the next part , we will take a look about the different modes and functions used in Emacs and also their usages. Till then, explore more material on internet about it and have fun in the geeks way with Emacs.

Pages : Follow ankurtwi on Twitter      


Ubuntu 10.04 was released last year but it’s still popular among most of the Linux users because of its eye catchy look. Moreover its a LTS release. First thing I noticed when I installed the distro was the missing network applet (bug) . Because of that I was unable to connect to the wireless network. I posted the same in the ubuntu forums community and figured a way out. I posted the solution over there  and it got great response in return too. It got 25,000+ views over there in the forums. Link for the same is http://ubuntuforums.org/showthread.php?t=1469625 . So I thought of sharing it over my blog too . Just follow the steps below and missing network applet will appear on your screen after reboot :

1. In the terminal type  “sudo gedit /etc/NetworkManager/nm-system-settings.conf” (without quotes)
2.Change the “managed=false” to “managed=true” and then save it.
3. Then in the terminal type “sudo killall nm-system-settings”
4. Reboot your system
This solution worked for me :)

Pages : Follow ankurtwi on Twitter      


Linux is generally considered as a geek’s operating system and I am completely agree with it. Linux is not only limited to work only. You can also enjoy a lot while working on it. There are many crazy commands which will bring a big smile on your face. Below we are going to discuss few out of them.

1. Oneko : This utility remembers me of the cat mouse game. Cat chases the mouse pointer regardless of its position. You have to download it from the repository by typing “sudo apt-get install oneko” (without quotes)  in ubuntu .Then just launch it by typing oneko . You will see a cat following your mouse pointer. You can terminate this command by using the famous Ctrl-c.

2. Xpenguins:  We all know about the  relationship  of the Linux with the penguin “Tux”.  By using this utility you will see penguins dancing around your desktop. This command is partially GUI based but can be invoked using the CLI. You can install it by using “sudo apt-get install xpenguins” and can invoke it simply typing xpenguins on your terminal. To terminate follow the same Ctrl-c rule.

3.  Fortune :  You can generate famous quotes using this. It uses the random function during the generation. You can find it in the “fortune-mod” package.  For the installation of the package you need to type “sudo apt-get install fortune-mod” . Launch it by typing  fortune . You can add it  in your bashrc file so that everytime you log in you see a message .

4. Cowsay and Xcowsay : Want to say something to anyone using a cow as a medium?? If yes this utility fits the best. CLI version is cowsay and GUI version is xcowsay . You can find them in the cowsay and xcowsay package respectively. To invoke follow the syntax : cowsay text (CLI) and xcowsay text(GUI) . Example – Let’s say “hello” through the cow.

cowsay hello

xcowsay hello

5. sl (oops ls) : As we all know that the “ls” utility (used for listing of files) is used at a very high rate in  Linux. But sometimes due to high speed typing we typed it “sl” and “ls”. If you had “sl” utility installed you will see a train engine passing by in your command line warning you that you have misspelled the ls. Install sl by using “sudo apt-get install sl”  and invoke it using sl.

There are lots of others crazy commands too. Google them and have fun!!!

Pages : Follow ankurtwi on Twitter      


Compression of files is a necessity these days. It’s not only helps you in saving your space but also helps you in quick sharing and back up purposes. Text files compresses more than the web images and videos because they are already in the compressed form .You must have observed many open source softwares  in the .tar.gz packages. These are the compressed file made out using the tar and gzip  (gunzip)  utility. So let’s get started with these great utilities :D

Tar : Good practice for compressing a file  is to archive the files first and then compress them. So to create an archive of a  disk archive that contains a group of files or an entire directory , we should use the tar utility. Another advantage of the tar is that it also compresses the file to some extent. So using tar with gzip means double layer compression. To use the tar we should need to know some of its options:

-c : Create an archive
-x : Extract from the archive
-t : Display the files in archive
-f : Specify the archive named as arch

Create the archive : You can create the archive by following the syntax tar -cvf  file.tar file1 file2  . For Example- We created an archive named as html.tar for the html folder  by using the command tar -cvf  html.tar html . As I told you above tar compresses the file also. You can easily see this in the below screenshot  :

compression by tar

Extracting files from tar archive : You can extract the files for tar archive using the  ‘-x’  utility.  Follow this syntax and your file will get extracted tar -xvf  file.tar  

Gzip or Gunzip : Using this utility on the tar archive file adds an another layer of compression. As a result of both you got the .tar.gz file format. Challenger of the gzip is the bzip2 utility because it compresses the file in the greater ratio. But bzip2 is a slow compression process. So it depends on your needs which utility to use.

Compress using gzip : You can compress with the gzip using the simple syntax of gzip  filename . We are compressing the html.tar archive  further using the gzip . You can also use the  ordinary files in the filename  instead of the archive. We can see the compression ratio by using ‘-l’ option along with this utility. Below is the screenshot of the same :

gzip compression

Extracting the gzip compression : You can easily extract the gzip utility by using either the “gunzip” command or by using the ‘-d’ option with the gzip. In short you need to follow the following syntax : gzip -d  filename.gz  or  gunzip  filename.gz.

I hope this tutorial will be useful for you. Suggestions,feedback and queries are always welcome.

Pages : Follow ankurtwi on Twitter      

Follow

Get every new post delivered to your Inbox.

Join 70 other followers

%d bloggers like this: