Tuesday 25 November 2014

Terminal Tweaks


As we all know Terminal is the heart of any Linux system. The newbies often find the terminal pretty boring to work on. But what if I say that you can have great fun with your terminal?

To do this, we will first learn about a file called the .bashrc, located at your home directory. This file takes care of your shell (command line) profile. The most common command line shell is the BASH, used in most of the Linux distros. General shell scripts are written to be run in BASH shells.

Any file with name preceded by a . is treated as hidden file, and hence it won't be shown generally in your file manager. In the terminal you must use ls -a to see the hidden files and directories.

The .bashrc file contains a list of commands which get executed whenever you start a terminal (bash shell). Open your terminal, and in your home directory type in cat -n .bashrc and see the output.
( cat prints the output of a text file, and -n option makes it show the line numbers as well. )



An important command, which must be mentioned here, is the alias command.
It has the general form,

alias <new command>=”<command>”

With the alias command you can give another name to a particular command.
Like, say, I type in the following and hit Enter :

alias welcome=”echo 'Hey there, how do you do?'”  

Now if I type in welcome and hit enter, the command echo 'Hey there, how do you do?' command will be executed, and hence the output:



So apparently, welcome becomes a new command. In this way you can see many aliases in the .bashrc file.

Now it is time to edit the file. Remember, you must not unknowingly delete any of the contents of the .bashrc file. It is always better to take a backup of the file.
Open the .bashrc file with any text editor, and now add the following line:

# Our own additions  


The # is used for one-line comments in BASH . The above line is for our reference, and to show that now on wards the commands are entered by the user, not by the system. Now we come to our tweaks one by one.

Advanced Copy and Move:


The first tweak is the advanced copy and move command. You must have noticed that copying or moving large files in terminal is faster, but you never get the progress of your ongoing work. The advanced copy/move commands will show you a progress command. Go to this link and follow the instructions (method 2 there is easier for newbies) . After this, your copy or move operation will look like this:



Delete with Prompt:


One of the deadliest command in Linux is the rm command. This command is used to delete a file permanently (rm means remove), without asking you for confirmation. For confirmation, you must use the -i option with rm. Many newbies confuse rm to be the rename (for renaming we use the mv command) command and hence may delete many files accidentally. I still remember, when I was a novice, I accidently deleted a movie approx 2 gigs, thinking that I am going to rename it!  So we can add this line to our .bashrc file :

alias rm=”rm -i”

Thus, now whenever you accidentally use the rm command, you get a confirmation that you are deleting the file. Thus better be safe than be sorry.



The Welcome Message:


You can make your terminal greet you whenever you open it. Just open .bashrc, add the following line at the end, and save the file:

echo “<your computer name> welcomes you, <your name>!”

e.g. in my laptop, I added:

echo “Blue-Dragon welcomes you, Vishwa Protim!”



System Information:


Another tweak which I recently found. The screenfetch command will generate your system information, with a beautiful output. First you need to type in the following commands:


mv screenFetch/ /opt/

Open .bashrc file, and add the following line at the end:

alias system='/opt/screenFetch/screenfetch-dev'

Save the file. Now reopen your terminal, and type in, system. Hit enter to see the magic.


Thus there are many such tweaks to make your Terminal experience wonderful. Also experimenting with the alias command and the .bashrc file can give you much customization. Feel free to add up your own customization here in the comment section.