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
$set -o emacs
$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.


Popular posts from this blog

Exploring Node.js Internals

I found a great article explaining Node JS internals, must read : Some other articles : Introduction to Node.js Being an official website, 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 Book This 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.js This beginner book goes beyond an explanation of the runtime. It teaches about packages and streams and creating a web server with the Express framework. LibUV This is the official documentation of the supporting C++ code of the Node.js runtime. V8 This is the official documentation of the JavaScript engine that makes it possible to write Node.js with JavaScript.

Hibernate Object Conversations

Session methods to use for object conversations Save() A new instance being attached to the session. An insert will be scheduled. Update() Call Update to make a transient object persistent again. It will force a SQL update on the transient object. This is because Hibernate does not know whether the object is dirty or not and to be safe by default schedules an update. This method will throw an exception, if the entity is already registered with the session. - NonUniqueObjectException is thrown. saveOrUpdate() Either a save or an update will be called based on whether the identifier exists or not. No identifier - save is called, else update is called. Or for a better understanding, if the object is transient, then a save is called, if the object is persistent, then an update is called. Reattaching an unmodified instance - If you know for sure that an object is not modified and you just want to make it persistent again - Session.lock(item, LockMode.No