Tuesday, October 4, 2011

Linux Command Line History

 1. Display timestamp using HISTTIMEFORMAT

For auditing purpose, it may be beneficial to display the timepstamp along with the command as shown below.


# export HISTTIMEFORMAT='%F %T '

# history | more


2. Repeat previous command quickly using 4 different methods

Following are the 4 different ways to repeat the last executed command.

    Use the up arrow to view the previous command and press enter to execute it.

    Type !! and press enter from the command line

    Type !-1 and press enter from the command line.

    Press Control+P will display the previous command, press enter to execute it


3. Search the history using Control+R

Press Control+R and type the keyword.


4. Execute a specific command from history


In the following example, If you want to repeat the command #4, you can do !4 as shown below.


# history | more

1  service network restart

2  exit

3  id

4  cat /etc/redhat-release


# !4

cat /etc/redhat-release

Fedora release 9 (Sulphur)


5. Clear all the previous history using option -c


# history -c


Reference: http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history

1 comment:

mahasiswa teladan said...

hi..Im college student, thanks for sharing :)