Skip to main content

Access old commands from history with just few keystrokes

One of the key feature of Unix shells like C shell , Bash shell and the Korn shell is history. The ability to recall and reuse commands that you have entered earlier can save many keystrokes of repetitive typing.

Launch any of the above mentioned shell on the command line by typing csh, bash or ksh. Now let start accessing old commands using history.

History let us recall commands and edit them before they are executed. Shell allows us to use different editing styles depending on what we are trying to do. The primary editors are vi, emacs, and gmacs. I recommend vi, as most people are familiar with it. History and command line editing behave very differently depending on whether we are using vi, emacs, or gmacs.

To set vi up as history editor type:
$set -o vi
or
$set -o emacs
or
$set -o gmacs

After setting “set -o vi" as our history editor, we can now access history:
  1. Press the escape key once (esc).
  2. Then press k to access last command that you typed will appear on the screen.
  3. Edit it if required as per the requirement and press enter to execute it.
Each time you press k you’ll go back one more command in your history. The minus key ( – ) works in exactly the same way. Press j or the plus key < + > to move forward in the command history. (When you are rapidly running back through history looking for the command you need, and you realize you’ve passed it, it’s good to know how to move forward again.)

If you have set -o emacs or gmacs, the keys are control-p for previous command and control-n for next command.

To view more of your history, type “history”, and a list of your most recent commands will be displayed along with numbers. If you see the number of a command that you need, recall it by hitting the esc key, type the number of the command as displayed by history, and then type an upper case G. This will place the command with that number on the command line.

We can also use vi editor search command to access particular command from the history:
  1. Press the escape key once (esc).
  2. Type “/” along with the keyword you want to search in the history. For example, let say if we have used “ls -l” previously we can acess it directly by:
    • $/ls
  3. Above command will give back “ls -l” on the command line.
  4. If we have multiple search results we can traverse through them using “n” for forward search and “shift + n” keystrokes for backward search in the history. Like we normally do in Vi Editor.
If you like the idea of history, ask your system administrator to change your shell to any of the above shell, and add set -o vi, emacs or gmacs into your .profile file.

Comments

Popular posts from this blog

JUnit – Run unit test in an Sequence / Order

In JUnit, we can use @FixMethodOrder(MethodSorters.xxx) to run the test methods in a sequence or order.

import org.junit.FixMethodOrder;import org.junit.Test;import org.junit.runners.MethodSorters;importstatic org.hamcrest.CoreMatchers.is;importstatic org.junit.Assert.assertThat;//Sorts by method name@FixMethodOrder(MethodSorters.NAME_ASCENDING)publicclassExecutionOrderTest{@TestpublicvoidtestB(){assertThat(1+1,is(2));}@Testpublicvoidtest1(){assertThat(1+1,is(2));}@TestpublicvoidtestA

Exploring Node.js Internals

I found a great article explaining Node JS internals, must read :

https://www.smashingmagazine.com/2020/04/nodejs-internals/


Some other articles :

Introduction to Node.jsBeing an official website, Node.dev explains what Node.js is, as well as its package managers, and lists web frameworks built on top of it.“JavaScript & Node.js”, The Node Beginner BookThis book by Manuel Kiessling does a fantastic job of explaining Node.js, after warning that JavaScript in the browser is not the same as the one in Node.js, even though both are written in the same language.Beginning Node.jsThis beginner book goes beyond an explanation of the runtime. It teaches about packages and streams and creating a web server with the Express framework.LibUVThis is the official documentation of the supporting C++ code of the Node.js runtime.V8This is the official documentation of the JavaScript engine that makes it possible to write Node.js with JavaScript. x