Sådan aktiveres tidtagning i History command?

The Bash history feature is an invaluable tool which allows users to recall commands previously entered into their shell with relative ease. This makes it easy to enter repeated commands and keep track of what was done on a system. By default, however, a user is unable to see whenthese commands were actually entered. When auditing a system, it can sometimes be useful to see this type of information, for example when trying to determine how and when a file may have gone missing on the file system. Since Bash version 3, however, you are able to enable time-stamping of entries for review later.
Applicable versions of Bash provide the environment variable HISTTIMEFORMAT which you can set for this purpose. Although it is empty by default, you can simple assign a time format string to enable time-stamping.

At the first run this command :

[Email protected] :~# history | tail -3
53 nano /etc/fstab
54 umount /mnt/NAS
55 mount /mnt/NAS

Enable timestamp in history command

To enable time stamp on your bash history type following command on your terminal:

[Email protected] :~# export HISTTIMEFORMAT=”%F %T “

Again execute history command :

[Email protected] :~# history | tail -3

53 2016–03–02 08:27:38 nano /etc/fstab
54 2016–03–02 08:27:38 umount /mnt/NAS
55 2016–03–02 08:27:38 mount /mnt/NAS

More help for set time format in date command manual page :

mand dato

Now you can Add it to your .bashrc file so it’s always there (if you like it, that is).

[Email protected]:~# vi .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1=’${debian_chroot:+($debian_chroot)}h:w$ ‘
# umask 022

# You may uncomment the following lines if you want `ls’ to be colorized:
# export LS_OPTIONS=’–color=auto’
# eval “`dircolors`”
# alias ls=’ls $LS_OPTIONS’
# alias ll=’ls $LS_OPTIONS -l’
# alias l=’ls $LS_OPTIONS -lA’
# Some more alias to avoid making mistakes:
# alias rm=’rm -i’
# alias cp=’cp -i’
# alias mv=’mv -i’

Thank You For You Attention , That’s it .

Giv en kommentar

Dette websted bruger Akismet til at reducere spam. Lær, hvordan dine kommentardata behandles.