Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I've been trying to get timestamps on the history command. I found the following
export HISTTIMEFORMAT="%F %T "
- and it works ok - but after I logout and log back in the history command is back to normal.
So I did a little more searching and found this
export HISTTIMEFORMAT='%F %T - %H:%M:%S ' >> ~/.bashrc
I thought exporting to .bashrc would "save" the command - but I guess I am wrong.
My questions is what do I need to do to get timestamps on history evertime I log on?
And additional question - how/where do I set it for all users?
Or, as an alternative to modifying /etc/profile ..
Create a file local_bash_stuff_with_a_long_funny_name.sh
under /etc/profile.d, make it executable and put that kind
of customisation in there.
That should survive upgrades - which may/could overwrite your
modified /etc/profile .
But I am not sure how to create a .sh file and what to do with it afterwards.
I opened the bashrc file, but I could not see the HISTTIMEFORMAT line anywhere. Doesn't export save the command in the file or do I have to put it there my self?
I opened the bashrc file, but I could not see the HISTTIMEFORMAT line anywhere. Doesn't export save the command in the file or do I have to put it there my self?
is to append the output from export HISTTIMEFORMAT='%F %T - %H:%M:%S ' to ~/.bashrc. What is the output from export HISTTIMEFORMAT='%F %T - %H:%M:%S '? You can find out by running it at a command prompt; it does not output anything. So that is exactly what is appended to ~/.bashrc.
"export" is used to set an environment variable. That is a variable which will also be set in any child processes the current process starts such as when you run a new command.
Now you have tested the command export HISTTIMEFORMAT='%F %T - %H:%M:%S ' and found it does what you want you presumably want to have it run automatically when you log on. Putting it in ~/.bashrc is one way of doing so. ~/.bashrc is simply a series of commands that are run during shell initialisation. It probably contains commands that are unfamiliar to you but you could type them all in at a command prompt.
So you do need to put export HISTTIMEFORMAT='%F %T - %H:%M:%S ' in ~/.bashrc. You could do that by using an editor or`you can append it from the command line using
And thanks for the detailed explanation.. that helps understanding instead of "just" giving me the right code.
My bashrc looks like this now for the history stuff - but although I have the ignoredups - I see duplicates. Is it wrong?
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# Timestamps on history commands
export HISTTIMEFORMAT='%F %T - %H:%M:%S '
At the start of the history list I have 20 entries from today, then 25 or 30 from yesterday and at the end again some from today... Why is that?
Last question (I think) can I use this
echo "export HISTTIMEFORMAT='%F %T - %H:%M:%S '" >> /etc/profile and then it affects all users?
benmie;3718549]that is just what I needed - I forgot the echo..
And thanks for the detailed explanation.. that helps understanding instead of "just" giving me the right code.
My bashrc looks like this now for the history stuff - but although I have the ignoredups - I see duplicates. Is it wrong?
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# Timestamps on history commands
export HISTTIMEFORMAT='%F %T - %H:%M:%S '
At the start of the history list I have 20 entries from today, then 25 or 30 from yesterday and at the end again some from today... Why is that?
benmie;3718549]And thanks for the detailed explanation.. that helps understanding instead of "just" giving me the right code.
Welcome. It was on the "Give a man a fishing rod ..." principle.
Quote:
Originally Posted by benmie
My bashrc looks like this now for the history stuff - but although I have the ignoredups - I see duplicates. Is it wrong?
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# Timestamps on history commands
export HISTTIMEFORMAT='%F %T - %H:%M:%S '
This may be a daft idea, but does the HISTCONTROL=ignoredups work if you remove the HISTTIMEFORMAT=?
For details on how the many possible bash initialisation files work (except the /etc/profile.d/* ones which may be Slackware specific ???) see the GNU Bash Reference. It is common practice to simplify this mechanism by making interactive login shells the same as interactive non-login shells by adding the following to /etc/profile, ideally in a bash-specific section
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.