Wednesday, October 14, 2015

How to imporve efficiency while working in Unix/Linux?

There are various flavors of Unix/Linux currently available in market.Below techniques which would be helpful to you while working in Unix/Linux. 

1. Using history command 


It is a Unix/Linux command used to get list of commands fired on Unix/Linux kernel.

You can use command  as  history | grep "mykeyword" to get desired list of commands which you have used recently.
HISTSIZE - a unix/linux environment variable, which specifies how many command history can store.

2. Using pipe (|) instead of two commands


Here, history and  grep command used to get the output of history command having "myword" word used in earlier command executions. 

3. Use  of ! and !! command


! command is used for to execute last command which is used in Unix/Linux, whether it successfully executed or not.

eg. 
In Unix, After doing ls –lrt myword.txt, I need to open the file myword.txt, you can use command like - vi !$.  Here !$ is the last argument of the shell.
In Linux, if you have installed vim editor , you can use it like  - !vim, 

This method saves your 30-35% time  time at a time of critical conditions.

Depending on Unix/Linux flavor and depends on shell, sometime SSH client like Putty, MultiTabbed Putty, etc. also require some settings, with that you can refer previous command with help of keyboard Up and Down arrows. 

!! command is used to execute the very last command you have executed and extremely fast as in processing. It works on the shells in which Up and Down arrow not working.


4. Use CTRL+R


It is used for repeating the last matching command.

Usage of this method is like that press CTRL+R and type "myword" which i have used in last command.Unix/Linux will find "myword" and once displaying the search result, you just need to press "Enter" to execute that command.

5. Use of aliases


You have to define aliases , in your  bash profile .profile or .bashrc file, which are used by your frequently while working. You can find this file by using ls -a command in your home directory.

eg. 
"l" which finds all files. 
"l." which finds all hidden files. 
"ls" which finds all files of using option - ls -lrt.
"cdh" which finds all files of using option - cd /home/myyword directory.

6. Using regular expression in grep and find and common commands like cd.

  
grep and find are two best commands provided by Unix/Linux mainly to search in a file , a directory , certain words in file e.g. ERROR or Warning.
eg.
grep "error" *.tmp  | grep "warning" *.tmp - Using two grep command for finding error and warning individually.
egrep "error|warning" *.tmp - Instead of  using two grep command for finding error and warning individually, usage of a single command.
cd  - to switch between two directories in Unix/Linux.

7. Use of CTRL+Z, fg and bg commands


Use  CTRL+Z and fg and bg to suspend a process running for a particular task.

Use fg and bg to run a particular command to run in background and foreground.
eg.
fg 1  - last background command or job to bring on foreground. 
fg 2  - second last background command or job to bring it on foreground.

Lastly, You have to Minimize the key strokes or increase the speed of typing, in Unix/Linux to get quicker output. You have to learn more n more commands with different options and usage of them, it will reduce your thinking time and increase your productivity. 


Some techniques might work in one flavor of Linux, but same might be not work for you.