Using the command line gives power and it is even better when you can manipulate text on the command line quickly. Debugging something that has gone wrong on a Linux Server is far easier and quicker than on Windows. Connecting to a Linux Server is usually faster than connecting to a Windows server since most Linux servers run without a GUI.

If you are investigating on a server and want to know since when it was up, who else is using the server and the CPU load you’d have to open the Task Manager and do multiple clicks to find these information on a Windows server. When you connect to a Linux server, you just type w , press enter that’s it. You have all that information :

metalinux@localhost:[~]: w
14:13:30 up 2 min,  2 users,  load average: 0.26, 0.29, 0.13
USER          TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root            tty1                                  14:13      10.00s  0.02s  0.02s -bash
metalinu   pts/0   192.168.100.5    14:12       2.00s  0.07s  0.03s w
metalinux@localhost:[~]:

Linux was built for performance. Windows was built for those who those who like clicking buttons and waiting! The development of the Linux shells over the years has known significant improvements and there are several tricks that can help you go faster with the command line. The most important of them all is the Tab key.

The Tab key will help you a lot of times to go faster when moving into directories and will prevent you from mistyping file and directory names. The tab key tries to autocomplete the string with a filename or directory. If just one filename or command matches the string you have typed, the shell will autocomplete it when you type the Tab button. For e.g. typing “cat /var/log/mess” and then pressing the Tab key would give “cd /var/log/messages”

However, if the string does not uniquely identify a command or filename, the shell provides the possible completions. For example, if one type “cd /etc/cr” and then presses the Tab Key the following will be displayed:

metalinux@localhost:[~]: cd /etc/cr
cron.d/       cron.daily/   cron.deny     cron.hourly/  cron.monthly/ crontab       cron.weekly/  crypttab
metalinux@localhost:[~]: cd /etc/cr

You need to type one or more characters to uniquely identify a possible completion. To get Tab to autocomplete “cd /etc/cron.weekly” you would need to type “/etc/cron.w”.

Tips that help you move on a line can be very helpful and make you gain much time. The arrow keys will naturally help you move a character to the left or right. To get things done like a pro you can try the following on your terminal:

Ctrl + or / Alt + B ==> Moves the cursor to the start of the word on the left

Ctrl + or / Alt + F ==> Moves the cursor to the end of the word on the right

Ctrl + A                  ==> Moves the cursor to the start of the line

Ctrl + E                  ==> Moves the cursor to the end of the line

Often, you will need to delete long chunks of text to the right or left of the cursor and the following combinations will help you go faster:

Ctrl + K  ==> Deletes everything onthe right of the cursor

Ctrl + U  ==> Deletes everything on the left of the cursor

Ctrl + W ==> Deletes the string between the cursor to the beginning of the word on the left

There will come times when you will need to copy a piece of text from one terminal to another.

Shift + Insert ==> Usually copies text from clipboard

Shift + Insert will usually do the job if your console has been setup to allow copying text from your computer to the console. If you are using an application like MobaXterm the combinations can be modified according to your taste. You can for example opt for Ctrl + V.

Typo errors are common and modifying characters and whole words rather than deleting and rewriting it can save a lot of time.

Ctrl + T ==> Inverts the position of two characters in front of the cursor [Ctrl + T on sl would give ls].

This correction needs two keystrokes to do rather than 4 with 2 x Delete to remove sl and then type l + s. While this might seem banal, you are saving 2 keystrokes on 4 or 1000 keystrokes for every 2000 errors you make. If you sum up all of that, you will have saved some time in your life while correcting typo mistakes 😊

Here are some more tips that will save you unnecessary keystrokes on a Linux terminal:

Alt + T ==> Invert the position of two words to the left of the cursor (Alt + T on “two one” would give “one two”). This one saves a lot of time rewriting the two words in the correct order

Alt + C ==> Switch a character to capital and move to the end of the word [Alt + C with the cursor on i of capital would give capItal]. Most of the people I met will delete the whole word and rewrite it correctly.

Alt + L ==> Switch the whole word to small letters [Alt + L on small would give SMALL]. Again, they will delete the whole word and rewrite it correctly.

Alt + U ==> Switch all characters of the word to capital letters [Alt + U on BIG would give big]. And again, they will delete the whole word and rewrite it correctly.

Alt + .  ==> Writes the last parameter given to the shell. Most do not know it can be done.

Sometimes unwanted output on the screen will annoy you and you might want to have a fresh screen.

Ctrl + L ==> Your terminal cleaner.

Do not worry, you need not rerun the commands to get the output again.

Shift + Page Up ==> Scroll up the terminal.

Shift + Page Down ==> Scroll down the terminal

It might happen that you want to rerun a command you entered earlier.

Ctrl + R ==> Searches for a command that has been entered earlier.

Press Ctrl + R repeatedly to go backwards till the first occurrence and Ctrl + S to search forward till the last occurrence.

The following combinations will help you quickly manage commands you have launched

Ctrl + C ==>  Stops the command that was launched

Ctrl + Z  ==> Pauses the command that was launched.

You can resume it by typing fg. This can be pretty useful if you want to consult a directory path while editing a file. Press Ctrl + Z to pause editing and send it to background, search for the things you need, type fg to get back to the editor. Most people would save the file, close the editor, search the needed term, open the editor again. It’s not bad a method, but you go faster and if you are an administrator these things will help you go faster in your work.

You can also stop typing exit or logout :

Ctrl + D ==> Closes the session and logs you out.

By default the terminal text prompts are white on black. You can make life more colourful. Add the following to your .bashrc file

  • Edit your bashrc [vim ~/.bashrc]
  • Insert this line ==> export PS1=”\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h:\[$(tput sgr0)\]\[\033[38;5;6m\][\w]:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]” [Shift + G to the bottom of the file, o to open a new line, Shift + Ins to paste the copied line]
  • Save and exit [:x]
  • Logout [Ctrl + D]
  • Connect again ==> Life changes from black and white to a colourful one

Before :

Linux default terminal

Linux default terminal

After :

Linux terminal with colours after modified .bashrc

Linux terminal with colours after modified .bashrc

Linux terminal with colours after modified .bashrc

Linux terminal with colours after modified .bashrc

Hope you enjoyed learning these tips and tricks. Leave your comments and questions right below if you have any difficulties using the shell, I will be very glad to help you out and learn at the same time. You can also ask for tutorials you would like to see. Do not forget to share and like! Go Linux!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s