Shell Programming Blog Shell Programming Blog

Saturday 13 October 2012

Linux bash scripting: How to search the command history (previously executed commands)

Unknown | 10:47 | |


Bash Linux Unix shell scripting

We often need to type long commands in the command line which we typed earlier. Instead of typing it again we can search the command history for the command we executed and execute it again. This technique will come handy when you are required to type a long command that you executed previously.

To search the command history and execute the command without editing it, Press Ctrl+R and type the keyword present in the previously executed command.

In the below example, I searched for the word "work", which displayed the previous command "cd /home/sittik/test/DDI/work" in the history that contained the word work.



Suppose if you need to edit the command before executing it, you can use the left or right arrow key without pressing enter. For example, you can search for "httpd" and which will display the command "service httpd stop" from the command history. You can change this command to "service httpd start" and execute it as shown below.




0 Comments:

   

Post a Comment

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
3. Please do not spam, spam comments will be deleted immediately upon my review.

Regards,
Mohamed Abubakar Sittik A

 

Shell Programming Copyright © 2012 Shell Programming theme is Designed by Abusittik, Shell Programming