CentOS Linux Server Guide

Centos Linux Command Line Operation

Using "history" command and <UP> <DOWN> Arrow Key

 

The easiest way to check and re-use the commands you previously entered, just <UP> or <DOWN> Arrow key to navigate and press <ENTER> key.

 

Meanwhile, the "history" command gives you the list of those commands that you have previously issue.

 

NAME
history

SYNOPSIS
history [OPTION]
 

Note: The command history of each user is kept in .bash_history in user home diretory


 
Command and options  Descriptions
history Using history command without any options,  the system will display the command history list with line numbers. Lines listed with a * have been modified.

 

history n n option, will output the last n lines on screen
history 5


598 su - jane
599 visudo
600 su - james
601 man history
602 history 5

 

history -w filename -w option, save the list of commands to a file. The following example, we are export our history command to filename called hisfile.
history -w hisfile

tail -3 hisfile
history 5
history 3 -w hisfile
history -w hisfile

 

history -c -c option, remove all the command history. The following example shows that we are clearing the previous history commands, the only command we see here is first command "history"
history -c


history
217 history

 

history -r -r option, this will read the history command we stored earlier from  a file. The example below,we are reading from  hisfile.
history -r hisfile
 

tail -n 4 hisfile
man history
history 5
history 3 -w hisfile
history -w hisfile
 

!! repeat the last command issue.
 ls -l *.log
-rw-r--r-- 1 root root 30116 Nov 26 19:51 install.lo

!!
ls -l *.log
-rw-r--r-- 1 root root 30116 Nov 26 19:51 install.log

 

![string name]

repeat the last command start with [string name]. The example below, we are repeating the last command strart with string l which is history number 434, ls -l*log.
history

434 ls -l *.log
1435 history
1436 cat /etc/syslog.conf
1437 history


!l
ls -l *.log
-rw-r--r-- 1 root root 30116 Nov 26 19:51 install.log

 

 

Back to Command Line Operation



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy