Difference between revisions of "Storing date / time along with commands in history"

From Notes_Wiki
m
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Storing date / time with history command=
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Shell configuration]] > [[Storing date / time along with commands in history]]


We can use following steps to ensure that date / time also get stored along with history commands:
We can use following steps to ensure that date / time also get stored along with history commands:
#Create file '<tt>/etc/profile.d/history.sh</tt>'
#Create file '<tt>/etc/profile.d/history.sh</tt>'
#Add following lines to file:
#Add following lines to file: <source type="shell">
#:<pre>
#!/bin/bash
#::#!/bin/bash
 
#::
HISTTIMEFORMAT="%y %m %d %T "
#::HISTTIMEFORMAT="%y %m %d %T "
HISTSIZE=100000
#::HISTSIZE=100000
HISTFILESIZE=100000
#::HISTFILESIZE=100000
export HISTTIMEFORMAT HISTSIZE HISTFILESIZE
#::export HISTTIMEFORMAT HISTSIZE HISTFILESIZE
</source>
#:</pre>
#<tt>chmod +x /etc/profile.d/history.sh</tt>
#<tt>chmod +x /etc/profile.d/history.sh</tt>




Note: Do not make mistakes in this file like adding 'exit 0'. All /etc/profile.d scripts are run directly from new shell which is getting spawned. Making mistakes in profile.d scripts may make shell inaccessible. Hence never experiment with new profile.d scripts on servers on which you have only remote access, like hosting services, cloud, etc. In case some mistake is already done you can refer to [[Deleting shell start-up scripts remotely without executing them]], to make system work again.
Note: Do not make mistakes in this file like adding 'exit 0'. All /etc/profile.d scripts are run directly from new shell which is getting spawned. Making mistakes in profile.d scripts may make shell inaccessible. Hence never experiment with new profile.d scripts on servers on which you have only remote access, like hosting services, cloud, etc. In case some mistake is already done you can refer to [[Deleting shell start-up scripts remotely without executing them]], to make system work again.
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Shell configuration]] > [[Storing date / time along with commands in history]]

Latest revision as of 07:45, 16 February 2023

Home > CentOS > CentOS 6.x > Shell configuration > Storing date / time along with commands in history

We can use following steps to ensure that date / time also get stored along with history commands:

  1. Create file '/etc/profile.d/history.sh'
  2. Add following lines to file:
    #!/bin/bash
    
    HISTTIMEFORMAT="%y %m %d %T "
    HISTSIZE=100000
    HISTFILESIZE=100000
    export HISTTIMEFORMAT HISTSIZE HISTFILESIZE
  3. chmod +x /etc/profile.d/history.sh


Note: Do not make mistakes in this file like adding 'exit 0'. All /etc/profile.d scripts are run directly from new shell which is getting spawned. Making mistakes in profile.d scripts may make shell inaccessible. Hence never experiment with new profile.d scripts on servers on which you have only remote access, like hosting services, cloud, etc. In case some mistake is already done you can refer to Deleting shell start-up scripts remotely without executing them, to make system work again.


Home > CentOS > CentOS 6.x > Shell configuration > Storing date / time along with commands in history