My family bought our first personal computer in the Windows dominated era. So, of course, Windows was the first operating system we started using. Not just that, we even used to enjoy it unless we started learning Linux and its various flavours. Why is it so? Well, I found it better than Windows in most of the cases. (Here is an article which discusses some reasons that make Linux a better operating system for users). But one thing remained insatiable was what makes typing the commands on Linux command line a better experience than clicking impressive GUIs?
Linux Command Line vs GUI
As the saying goes, “we learn it best when we do it ourselves”, therefore after switching to Linux I personally felt the efficiency and quickness of tasks getting done through command line verses through graphical user interface (CLI vs GUI). And the major reason being, even a mouse click generates an action which will trigger the execution of the same executable as we do through the command directly. Hence, running the same task through GUI involves an extra overhead of calculating the mouse pointer coordinates, raising a click action etc. In case, there are input options required, it adds on to the overhead. All this handling of the overhead takes some time at the cost of impressive visuals and to avoid typing.
Well, to talk about deep driven merits of using command line as compared to GUI, here is a synopsis of abstract points:
Agile and Time-saving
Since through command line we are just triggering the executable which makes it faster than any GUI operation which involves parsing actions, inputs and displaying outputs. As a simple comparison exercise, install VLC player using its installer, which is GUI download/installation, and through the command line by running the following command.
$sudo apt-get update $sudo apt-get install vlc
Feel the difference in the amount of time one needs for the installation in both the cases.
A Linux command line user will rarely need a mouse device. From my own experience, just using keyboard is much convenient and as we develop the skill, its way more faster than using mouse. Believe it or not, but just using keyboard and typing every damn command sharpens our memory too.
Running commands offer a better understanding of how system works than any GUI alternative. Moreover, as we use commands, we implicitly memorize many and we give ourselves an opportunity to learn more.
Many of the redundant group tasks can be easily scripted and performed using those scripts. For example, if we have a huge set of files that needs to be renamed and then moved to another destination. With the GUI, it might be a tedious one for each one of the file, but with scripts its just about one logic in the script and running the script.
Do you think typing is a hassle with command line, especially with the long directory paths? There are some interesting conducive ways to avoid that. We shall learn more in the later sections.
Commands are any way more powerful in terms of options from any GUI alternative. To conclude, the efficiency and several micro-seconds of time saved in each command, really makes tremendous and precious value addition in the life of Linux users.
Remember for every small task we want out of the operating system, there exist a command or a key combination. Here in further sections we shall learn about certain Linux command line utilities which are not popular but are still a good alternative to GUI for some common tasks.
Assumption All the commands discussed have been tested with bash shell on Ubuntu 12.04.
Shutdown and reboot the system
When we click on the “shutdown..” action menu or button, it actually calls a command internally.
Linux gives us a simple command with the simplest name to remember
Here is its man page. The user needs root privileges to run this command.
Now we will discuss what all it has to offer.
1. We can even schedule a shutdown using one of its argument specifying time. The time can be specified in a phrase like ‘now’ or in minutes, minutes or hh:mm where ‘hh’ specifies the hours and ‘mm’ specifies the minutes in the time.
Therefore after/at specified time, the shutdown is initiated.
As an example, try
2. One can even restart the system through
$shutdown -r 3
It informs and alerts us about the reboot as
Broadcast message from rupali@home-OptiPlex-745 (/dev/pts/0) at 10:16 ... The system is going down for reboot in 3 minutes! Broadcast message from rupali@home-OptiPlex-745 (/dev/pts/0) at 10:17 ... The system is going down for reboot in 2 minutes! Broadcast message from rupali@home-OptiPlex-745 (/dev/pts/0) at 10:18 ... The system is going down for reboot in 1 minute! Broadcast message from rupali@home-OptiPlex-745 (/dev/pts/0) at 10:18 … The system is going to reboot now!
There is another way to reboot the system, and that is through the ‘reboot’ command.
Here is how it looks like when we run the command
Broadcast message from rupali@home-OptiPlex-745 (/dev/pts/0) at 10:18 … The system is going to reboot now!
Not one, but there are many text-based command line web browsers available for Linux. Such kind of command line web browsers may not be as fancy as our usual browsers. As a user, we all know fancy stuff comes with a compromise on efficiency. However, such simplistic command line browsers are pretty suitable for normal browsing and study.
One of such web browser is Lynx. The first and foremost step is to install it
$sudo apt-get install lynx-cur
After the installation is complete, launch the web browser by
And we get the following screen
We need to know following basic help information to starting using the ‘lynx’ text based browser
Commands: Use arrow keys to move, '?' for help, 'q' to quit, '<-' to go back. Arrow keys: Up and Down to move. Right to follow a link; Left to go back. H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list
To enter a URL, press ‘g’. Type the website URL one wishes to open. Lets type and enter mylinuxbook.com
Check out the following snapshot with our input URL
(Click to Enlarge)
We get the website opened in our browser which looks like:
(Click to Enlarge)
Navigate through the website by using up and down arrows. As we move up/down, the selected link gets highlighted. And we click a particular link by pressing ‘enter’.
For me, I select the ‘commands’ link from the menu available
After selecting ‘commands’ menu item, I press ‘enter’, which leads me to the relevant web-page.
(Click to Enlarge)
Note that, the top header menu remains the same for all the web pages of this website.
To go back, use left arrow key. Any time, we need to open a different URL, press ‘g’ and enter the URL. Lynx comes with a man page for its usage information.
However, we shall not go much in the details of the usage of web browsers as every text based web browser would have its own different ways to use.
A few known browsers are:
I don’t recommend any specific browser, feel free to explore the available ones and set your preference.
In this connected world, are we too addicted email clients? In our CLI Linux world, we can’t afford not to have a command line based email clients on Linux. Command line email client tools are powerful in terms of performance, and very easy to configure and use. However, to be candid, for someone who needs an interaction-impressive email client, command line based email client tools are not for them.
First of all, let us go ahead installing ‘mutt’ on our linux system, which can be done by following command
sudo apt-get install mutt
While we run this command, on my ubuntu 12.04 system, it asks
Need to get 2,682 kB of archives. After this operation, 7,523 kB of additional disk space will be used. Do you want to continue [Y/n]?
Type ‘y’ and press enter to the above prompt. And then it asks for certain basic configurations with a text based in-terminal screen. Following is a snapshot
(Click to Enlarge)
Since it is purely text based, mouse won’t work here. To select ‘OK’, press right arrow and then press ‘enter’. Further we get following screen, where we need to select a general type of mail configuration
(Click to Enlarge)
Since, in this article we aim to configure our ‘www.gmail.com’ account email to this email client, hence we need to select “Internet Site”. Here is a link to know more about postfix configurations.
Similarly select ‘OK’ by right arrow and pressing enter.
Next it asks us the system mail name. The information on the screen also explains
│ Thus, if a mail address on the local host is email@example.com, the │ │ correct value for this option would be example.org.
Therefore, in case I, type ‘gmail.com’. After typing, select ‘OK’ and press enter, which completes the ‘mutt’ installation and basic configuration.
However, we are still one step away from using the mutt email client. What is that one step? It is the client configuration and customization. Creating the directories for caching headers and bodies along with certificates
$ mkdir -p ~/.mutt/cache/headers $ mkdir ~/.mutt/cache/bodies $ touch ~/.mutt/certificates
Thereafter, creating a ‘.muttrc’ file in the home directory having the following customised settings
Notes (Before you proceed further)
- We are connecting it to the Gmail mail, which is an IMAP mail server
- Replace all ‘firstname.lastname@example.org’ with your email account
- One can also configure it with our password, but I won’t recommend the password to be mentioned in any clear form in any file on our system. Hence, leaving it to be prompted for whenever required.
# The gmail account details. Please change it to suit you. set imap_user = "email@example.com" set smtp_url = "smtp://firstname.lastname@example.org:587/" set from = "email@example.com" set realname = "Rupali" # Set your favourite editor here set editor = "vi" # Certain configurations set folder = "imaps://imap.gmail.com:993" set spoolfile = "+INBOX" set imap_check_subscribed set hostname = gmail.com set mail_check = 120 set timeout = 300 set imap_keepalive = 300 set postponed = "+[GMail]/Drafts" set record = "+[GMail]/Sent Mail" set header_cache=~/.mutt/cache/headers set message_cachedir=~/.mutt/cache/bodies set certificate_file=~/.mutt/certificates set move = no set include set sort = 'threads' set sort_aux = 'reverse-last-date-received' set auto_tag = yes ignore "Authentication-Results:" ignore "DomainKey-Signature:" ignore "DKIM-Signature:" hdr_order Date From To Cc alternative_order text/plain text/html * auto_view text/html bind editor complete-query bind editor ^T complete bind editor noop # Gmail-style keyboard shortcuts macro index,pager y "unset trash\n " "Gmail archive message" macro index,pager d "set trash=\"imaps://imap.googlemail.com/[GMail]/Bin\"\n " "Gmail delete message" macro index,pager gi "=INBOX" "Go to inbox" macro index,pager ga "=[Gmail]/All Mail" "Go to all mail" macro index,pager gs "=[Gmail]/Starred" "Go to starred messages" macro index,pager gd "=[Gmail]/Drafts" "Go to drafts"
Now we are all set to use the email client ‘mutt’. Run it by running following command
A blank screen turns up, which prompts for the password at its bottom-most list
Password for firstname.lastname@example.org@imap.gmail.com:
Enter your password and it will start loading your mails for you to access. Here is how it showcases your mails.
Check out the top highlighted line which is a basic help segment always available, intimating basic key options. Here are the commonly used ones
Up/Down Arrow: Navigate the messages Enter: Select the message q: To Quit the tool or return to the message list view d: Delete a message u: To Undelete a mail s: To Save a mail m: Initiate composing a mail r: To Reply g: A group reply ?: Need a Help
While composing a mail/reply, your favourite editor shall be opened as mentioned in the ‘.muttrc’ by us.
Well, mutt client agent has a lot more options and customisations as we start using it. This article shall not delve into all those usage information details which can be referred here.
However, there are other such command line email clients also available, such as
Editing images is no longer a professional’s effort in this era of social networking websites, most of us are living in. Of course, GUI has enhanced certain editing features as for example, say cropping. No doubt about that. However, think of cropping like hundreds of images to the same size. I am pretty sure, it wouldn’t be a pleasant experience with GUI applications any more. Besides, still most of the other image editing features are efficiently done through command line, without depending on any GUI application functionalities. Moreover, if the image editing is to be done on a number of images, command line tools is the most convenient rescue.
Linux gives us one such superb image format converter and editor which is imagemagick.
It is installed with the package ‘imagemagick’
$sudo apt-get install imagemagick
Imagemaick is like a suite of command line utilities for image operations. Here is a list of all the utilities which come within, descriptions taken from the man page.
Note: As an example image for all the illustrated example usage, we have taken following image called ‘orig.png’
displays an image or image sequence on any X server.
So, lets ask it to display the image, which can be done by
And here is what we get, A dialog window with the image displayed.
convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. The umbrella of benefits also includes the scenario where a thumbnail picture can be dexterously created in an autoscript of any application by just resizing any picture. Now we know, how might facebook has the thumbnail ready as soon as we upload our profile picture.
convert -resize 30x30 orig.png resized.png
The resulting thumbnail is:
To check out an example of the image effects it can do, try
convert -monochrome orig.png m.png
Here it edits the image to convert into a black and white monochrome effect, and save it to a separate ourput file m.png. Here is how the output file looks like
‘convert’ is also capable of converting from one image file format to another. Here is how that works specifying the compression level of the converted format JPEG.
$ convert -quality orig.png converted.jpg
Using ‘convet’ tool, the linux users have the capability to do image effects, resize and even rotate the image. Checkout this interesting set of effects of our image.
$ convert orig.png -rotate 180 -emboss 1 -quality 90 new.jpg
Our output image is, the penguin looks beautiful to me
More effects and options of ‘convert’ can be referred to from its man page.
describes the format and characteristics of one or more image files.
Trying it out on our original image,
$ identify orig.png
What I get is,
orig.png PNG 198x264 198x264+0+0 8-bit DirectClass 62.5KB 0.000u 0:00.000
If one doesn’t understand, what the output means, verbose output is obtained by
$ identify -verbose orig.png
A detailed output looks like,
Image: orig.png Format: PNG (Portable Network Graphics) Class: DirectClass Geometry: 198x264+0+0 Resolution: 72x72 Print size: 2.75x3.66667 Units: Undefined Type: TrueColorMatte Endianess: Undefined Colorspace: RGB Depth: 8-bit Channel depth: red: 8-bit green: 8-bit blue: 8-bit alpha: 1-bit Channel statistics: Red: min: 0 (0) max: 255 (1) mean: 141.496 (0.554886) standard deviation: 61.8626 (0.242598) kurtosis: 0.0347628 skewness: -0.547966 Green: min: 0 (0) max: 255 (1) mean: 147.828 (0.579719) standard deviation: 60.3165 (0.236535) kurtosis: 0.504549 skewness: -0.947011 Blue: min: 0 (0) max: 255 (1) mean: 140.783 (0.552089) standard deviation: 66.8083 (0.261993) kurtosis: -0.311562 skewness: -0.855471 Alpha: min: 255 (1) max: 255 (1) mean: 255 (1) standard deviation: 0 (0) kurtosis: 0 skewness: 0 Image statistics: Overall: min: 0 (0) max: 255 (1) mean: 107.527 (0.421673) standard deviation: 82.7262 (0.324416) kurtosis: -1.45325 skewness: -0.185137 Rendering intent: Undefined Interlace: None Background color: white Border color: rgba(223,223,223,1) Matte color: grey74 Transparent color: none Compose: Over Page geometry: 198x264+0+0 Dispose: Undefined Iterations: 0 Compression: Zip Orientation: Undefined Properties: date:create: 2013-05-10T22:14:27-07:00 date:modify: 2013-05-10T22:14:27-07:00 signature: 4fa517adcf20cdc524027ac621ba437e38635f21443781678830f3e75d890f15 Artifacts: verbose: true Tainted: False Filesize: 62.5KB Number pixels: 52.3K Pixels per second: 5.227M User time: 0.010u Elapsed time: 0:01.009 Version: ImageMagick 6.6.2-6 2011-03-16 Q16 http://www.imagemagick.org
resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. Mogrify overwrites the original image file, whereas, convert writes to a different image file.
To see how it works differently as compared to ‘convert’, do the following :
First of all, because we are expecting the original image to be overwritten, lets create a copy of our original one, as we need to use the original one for other imagemagick tools too.
$cp orig.png oimg.png $mogrify -monochrome oimg.png $display oimg.png
As a result of ‘display’ command, we get
Most of the mogrify options are similar to the ‘convert’ ones.
overlaps one image over another.
This is going to be really amazing. It takes a lot of mouse click efforts to overlap two images in any image editor, here it just takes the following command
$composite thumbnail.png new.jpg overlapped.png
The output image ‘overlapped.png’ is
Create a composite image by combining several separate images. The images are tiled on the composite image optionall adorned with a border, frame, image name, and more.
With ‘montage’, it creates a collage kind of collection of images in a geometrical way. The generic syntax to use ‘montage’ is
montage input-file [options] output-file
Note, the input file in above can be a set of files separated by spaces
For example, we shall be creating a composite image with all the effects and editing on our original image. Initially lets create several images with different effects using following simple ‘convert’ command
$ convert -implode 1 orig.png implode.png $ convert -monochrome orig.png mono.png $ convert -charcoal 3 orig.png charc.png $ convert -emboss 6 orig.png emboss.png $ convert -resize 60x60 orig.png resized.png
With each of the above five commands, we get five differently edited images, and including the original, we have total six images in total to create a composite image.
Now, we use the ‘montage’ tool to create a collage as follows:
$montage *.png montage.png
The figure below is how our output image looks like
Note, the way the images have been composited to create the final output image. It offers various options, including to change the geometry of the images, more details of which can be referred through its man page.
Mathematically and visually annotate the difference between an image and its reconstruction.. This is a very useful tool, especially for image processing professionals who need to monitor every pixel variation. As an example, let us compare two different formats of same image.
$compare orig.png converted.jpg diff.png
The way it illustrates a comparison visually is in the form of a diff image,
Mathematically, it compares two images as
$compare -metric AE orig.png converted.jpg diff.png
We use the option -metric which needs a metric type. In this example, we use ‘AE’ which corresponds to Absolute Error. More information regarding metric and metric types is here
For the metric type = AE, we get difference output as,
Animates an image sequence on any X server.
I am pretty sure you would love this tool. Remember the earlier days, where animations were created by drawing several and several drawings depicting a change in the overall movement. Similarly, this tool works on the same concept of principle. As a simplest example, lets create certain images of varying sizes in a separate directory.
$mkdir animation $cp orig.png animation/0.png $cd animation $convert -resize 10x10 0.png 1.png $convert -resize 20x20 0.png 2.png $convert -resize 30x30 0.png 3.png $convert -resize 40x40 0.png 4.png $convert -resize 50x50 0.png 5.png $convert -resize 60x60 0.png 6.png $convert -resize 70x70 0.png 7.png $convert -resize 80x80 0.png 8.png $convert -resize 90x90 0.png 9.png $convert -resize 100x100 0.png 91.png $convert -resize 110x110 0.png 92.png $convert -resize 120x120 0.png 93.png
Now, run the animation as
Use your creativity cells to create such animations and we would love to hear about them.
Command Line Terminal Shortcuts
In the initial section above, we discussed that for using command line for all kinds of tasks will result in a lot of typing. I never denied that a lot of typing can be cumbersome, especially when it comes to long file names, at times re-typing commands, etc. Although, we cannot completely avoid typing but Linux does come with a way to minimize certain difficulties. In this section we shall be discussing a few fantastic key combination short cuts which can be used while working on Linux terminal.
CTRL + r
This is an exciting short cut to search through the list of commands we’ve run in a terminal. We can even edit the already run command and then run it with the modification. As in, suppose we once copied a file ‘f1’ from a directory path to another destination path. Now we would like to copy file ‘f2’ from the same source path to the same directory path.
We can re-use are earlier used command as
1. Press key combination ‘Ctrl + r’
We get following just below command prompt
2. Type cp.
Basically, type the initial matching characters of the relevant command. More the relevant characters we type, quicker we’ll encounter the matching needed command from the already run commands.
3. Keep pressing ‘Ctrl + r’ until it displays our needed ‘cp’ command from the list of earlier used commands.
$ (reverse-i-search)`cp': cp /home/rupali/programs/cstatic/f1 /home/rupali/out/dest/
4. Once it shows our relevant command, press right arrow key (or left arrow key) to come out.
5. Make modification to change the filename from ‘f1’ to ‘f2’ and then run the new modified command.
cp /home/rupali/programs/cstatic/f2 /home/rupali/out/dest/
Therefore, it helped us to avoid re-writing the complete ‘cp’ command. It is an immensely useful key combination in Linux.
To check and run the recently run commands in a terminal. As an example, we are debugging an application and every time we make a change in the source, we have to run our ‘make’ command. We don’t need to type ‘make target’ again and again as it is the one of the most recent command in the command history. Just use up arrow to browse through recently run commands and run it from there.
The same can also be done using key combination ‘CTRL + p’.
To see how that works, run command ‘ls’ on your command prompt. After the command output, press up arrow key. You’ll find ‘ls’ command, which is the recent command which we just ran.
CTRL + a and CTRL + e
At times, we are typing our command and then notice we need to add ‘sudo’ in front of the command. We can use the key combination ‘Ctrl + a’ to reach the beginning of the command. The same can be achieved by ‘home’ key.
Similarly, we can use the key combination ‘Ctrl + e’ to reach the end of the command. Again, the same can also be done by ‘end’ key.
Tab key is the most used among the Linux users. When we are typing a file/directory path, ‘tab’ key assists in auto-complete as we move along with the path.
The way how it works is, type the initial characters identifying the directory name in the path of the filename, and press ‘tab’ key. It will be auto-completed in case the initial few typed characters uniquely identify it. Otherwise, it will suggest the possible names.
For example, try
and then press tab key. It will be be auto-completed to
In this way, we can easily type and auto-complete a long path as well conveniently.
CTRL + l
One can clear the terminal using ‘ctrl + l’ key combination. It has the same effect as the clear command. So, no need to type ‘clear’ command again and again.
CTRL + u
Clears all the text to the left of the current cursor on the command prompt.
CTRL + k
ALT + d
Note, this involves ‘Alt’ key and not the ‘Ctrl’.
Other keyboard shortcuts
The other keyboard shortcuts like opening a terminal, searching in the filesystem, etc can depend upon the distribution of the linux used. However, they are even changeable from the system preferences.
As in, in case of ubuntu, we the keyboard shortcuts can be found under
System > Preferences >Keyboard Shortcuts
Following is the snapshot depicting the same.
Well, from the above key shortcuts, we see Linux really values our typing and helps us in all ways in saving our effort of typing something which has been typed once.
NOTE – To learn some amazing Linux command line tricks, read our article on 20 interesting and extremely helpful Linux command line tricks
This article is an effort to widen the scope of using more and more Linux command line which is much faster and effective along with aiding self learning. Believe me, there are plethora of command line Linux utilities and tricks available for each and everything that can be done on an operating system. So, it is an endless topic. Would love to hear about more command line Linux powerful tools.