Wednesday, July 18, 2007

more with linux command named history

As we go along with our daily linux routines, be on server or with our power desktops, we could think and backtrace a specific command that we just keep on forgetting.

Linux history command reminds us the past linux command done by a specific user. By default, without any parameters, history list out all the commands entered by the currently logged-in user regardless of the command has been successfully executed or not.

Issued as root, this would show you root history commands in numbered format.

# history

Clearing out which is not really a good idea:

# history -c

Try clearing it out and show the history commands again like so
# history -c
# history

This would show you the history line marker and the last linux command issued by the currently logged-in user.


Moreever, these list of history commands refer to /root/.bash_history if you are using root. It follows the format of ~username/.bash_history by default. So vertito user has ~vertito/.bash_history file.

However, be reminded that this history file can be forged, edited, deleted, and most likely be purged. Additionally, the maximum number limit for history lines can also be modified using bash environment when a user logs in with his default bash profile. Not to mention, size of the history file could also be restricted to a certain file size.

Below are the basic variables related to setting history setting from bash profile.

USERNAME
HISTFILESIZE
HISTFILE
HISTSIZE
HISTCONTROL

Example additional contents of .bash_profile with regards to history linux command:

HISTSIZE=2
HISTCONTROL=ignoredups
HISTFILESIZE=4

This means, the maximum number of history lines would be 2 lines, ignoring any duplicate commands with a maximum filesize limit of 4 Kbytes only.

More arguments / option for history command :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-c Clear the history list by deleting all the entries.
-d offset Delete the history entry at position offset.
-a Append the ‘‘new’’ history lines (history lines entered since the beginning of the
current bash session) to the history file.
-n Read the history lines not already read from the history file into the current
history list. These are lines appended to the history file since the beginning
of the current bash session.
-r Read the contents of the history file and use them as the current history.
-w Write the current history to the history file, overwriting the history file’s
contents.
-p Perform history substitution on the following args and display the result on the
standard output. Does not store the results in the history list. Each arg must be
quoted to disable normal history expansion.
-s Store the args in the history list as a single entry. The last command in the
history list is removed before the args are added.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Take note that "history" is not a binary file, not like echo, it's a builtin bash command from bash shell.

0 comments:

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