LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-13-2009, 04:50 AM   #1
benmie
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Rep: Reputation: 0
Question Getting HISTTIMEFORMAT to work after logout


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?

Thanks for helping

BenMie
 
Old 10-13-2009, 08:06 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Logging out completely, not just that xterm, but completely logging out, then back in should work.
To set for all users, add to /etc/profile.
 
Old 10-13-2009, 08:33 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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 .



Cheers,
Tink
 
Old 10-14-2009, 01:30 AM   #4
benmie
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Ok, I will try that :-D

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?
 
Old 10-14-2009, 02:09 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
export creates an entry in your environment; it does not save it to a file; you might not want that.
Add the line into your .bashrc or .bash_profile.
 
Old 10-14-2009, 02:11 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by benmie View Post
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?
The effect of
Code:
export HISTTIMEFORMAT='%F %T - %H:%M:%S ' >> ~/.bashrc
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
Code:
echo "export HISTTIMEFORMAT='%F %T - %H:%M:%S '" >> ~/.bashrc
 
Old 10-14-2009, 02:37 AM   #7
benmie
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks catkin

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?

Last question (I think) can I use this
echo "export HISTTIMEFORMAT='%F %T - %H:%M:%S '" >> /etc/profile and then it affects all users?

Last edited by benmie; 10-14-2009 at 02:47 AM.
 
Old 10-14-2009, 02:49 AM   #8
benmie
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Original Poster
Rep: Reputation: 0
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?

Last question (I think) can I use this
Quote:
echo "export HISTTIMEFORMAT='%F %T - %H:%M:%S '" >> /etc/profile
and then it affects all users?
 
Old 10-14-2009, 01:32 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by benmie View Post
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?
I'll hazard a guess; you had a shell open from the day before, and
it got closed after one you had opened today.

To avoid that kind of issue have a look at
http://www.linuxquestions.org/questi...83#post2974983

Quote:
Originally Posted by benmie View Post
Last question (I think) can I use this
and then it affects all users?
You could ... might as well do >>/etc/profile.d/mylongextrastuffforbash.sh
as discussed previously ;}



Cheers,
Tink

Last edited by Tinkster; 10-14-2009 at 01:38 PM. Reason: added link to old post
 
Old 10-14-2009, 02:47 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by benmie View Post
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 View Post
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
Code:
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HISTTIMEFORMAT in script problems. ncsuapex Programming 2 06-26-2008 02:10 PM
history with time stamps not working, HISTTIMEFORMAT mohammednv Linux - General 1 02-02-2008 08:06 AM
logout wouldn't work (fixed) mimithebrain Linux - Software 2 04-13-2006 11:05 AM
Weird! ATI Drivers work only after logout, followed by "startx" in prompt pitchaxistheory Mandriva 1 10-14-2004 05:51 PM
logout in x doesn't work and nvidia doesn't boot Meriadoc Linux - Newbie 2 06-18-2004 12:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration