Unix history commands for Java developer productivity

When you are using Linux/Unix command line frequently, using the history effectively can be a major productivity boost. You can accomplish things with less typing. For example, you will be typing lots of commands like


and so on. There are 6 ways to repeat your previous commands quickly without having to type a lot.

  1. Use the up arrow to view the previous command and press enter to execute it.
  2. Type !! and press enter from the command line to execute the last command again
  3. Type !-1 and press enter from the command line  to execute the last command !-2 for command before the last and so on.
  4. Type history followed by enter, which prints a list of last few commands, and then !25 to execute a particular command
  5. Press Control+P will display the previous command, press enter to execute it.
  6. Press Control + R, and then search for the command or arguments typed. This the most useful one.

To execute the command  pwd again, you can do


Now, what if you want to execute a previous command that starts with certain letters


to execute the pwd command again. The most useful command  of all is

Control+P type “<search text>”

This a contextual search of your command history. As you type the search text, the display changes. The most powerful, and useful.

By default, history is stored in ~/.bash_history and ~/.sh_history files. You can list the hidden files with

~ is the home directory.

You can clear all the previous history with

You can do a lot more, but for Java developers, this is a good start.


Java & Big Data Interview FAQs

Java Key Areas Interview Q&As

800+ Java Interview Q&As

Java & Big Data Tutorials

Top