Sunday, July 6, 2008

Linux: Command Line History Recall

As soon you as you finished issuing linux commands, these commands are being saved and stored to a shell's history file, which you can further review to recall old and recently issued shell commands. The file is being saved to .bash_history file, which is located under your home folder. Each user has its own history file by default OS tweak. Like , user account peter has a history file stored to ~peter/.bash_history.

Now, to view the recorded history commands , simply issue

# history

To view explicit lines of history commands, issue history followed by number of lines to display

# history 10

The above command displays 10 recently issued commands from CLI terminal. Here is the command output of  the above command

# history 10

1073  cd /etc/
1074  nano -w php.ini
1075  cd /usr/share/wordpress/wp-content/plugins/
1076  ls -la
1077  wget -c http://downloads.wordpress.org/plugin/wp-dbmanager.2.30.zip
1078  wget -c http://downloads.wordpress.org/plugin/wp-ban.1.30.zip
1079  unzip wp-ban.1.30.zip
1080  unaip wp-dbmanager.2.30.zip
1081  unzip wp-dbmanager.2.30.zip
1082  history 10


You can actually recall a recently issued CLI command. To recall or re-issue a recently history command, say command number 1077 , simply

# !1077

That is a combination of exclamation mark followed by history line number. The above executes history command number 1077 which is equivalent to issuing

wget -c http://downloads.wordpress.org/plugin/wp-dbmanager.2.30.zip

Now, to issue the most recent and previous issue CLI command, simply

# !!

That is double exclamation point. The above history shortcut command reissue the most recently executed command from CLI. This history recall commands are very useful specially if you are dealing with linux command followed by long folder name and file locations.

HTH

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy