LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-27-2015, 09:31 AM   #1
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Rep: Reputation: Disabled
How: date of the command ran?


Hi Forum members,

I'm interested to get the date on which particular command was ran.

I've below in my .bashrc

Code:
export HISTTIMEFORMAT="%d/%m/%y %T "
I ran history | grep "cp" | less

I get an output like:

Quote:
1288 27/05/15 09:12:55 sacct -j 767151 --format=elapsed,ncpus,state
27/05 is today's date. But I'm interested for the date, the above output was ran.

What am I missing?
 
Old 05-27-2015, 10:06 AM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,168
Blog Entries: 10

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
all timestamps in the .bash_history file will have the date of the HISTTIMEFORMAT, of the time it was first run.
all successive timestamps will have the date/time it was ran.

Also, it doesn't appear that you sourced ~/.bashrc after editing?
Code:
source ~/.bashrc
or close whatever terminal you have open and relaunch it. Logout and back in works also.

So, if you ran this cp command yesterday, but used HISTTIMEFORMAT function today, you will only see today's date/time on the cp command from yesterday.
 
Old 05-27-2015, 10:26 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
You can get this info plus more details with BSD process accounting. You need a kernel with this enabled and gnu acct package.
 
Old 05-27-2015, 10:32 AM   #4
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
Hi Habitual,

Thanks for your reply.
I'm on SLURM job shceduler environment. Red Hat Enterprise Linux Server release 6.6 (Santiago)

I sourced .bashrc, that is why I know am able to see the date and time.
I logged out, logged in. Seems the error hasn't gone yet.

I ran same grep-history-cp command, got an output like:

Quote:
2941 27/05/15 10:29:39 cp assembly_pipeline.sh ../bin/
export HISTTIMEFORMAT="d/m/%y %T "

Now, how to fix it?

Best,
pL

Quote:
Originally Posted by Habitual View Post
all timestamps in the .bash_history file will have the date of the HISTTIMEFORMAT, of the time it was first run.
all successive timestamps will have the date/time it was ran.

Also, it doesn't appear that you sourced ~/.bashrc after editing?
Code:
source ~/.bashrc
or close whatever terminal you have open and relaunch it. Logout and back in works also.

So, if you ran this cp command yesterday, but used HISTTIMEFORMAT function today, you will only see today's date/time on the cp command from yesterday.

Last edited by publicLearner; 05-27-2015 at 10:34 AM.
 
Old 05-27-2015, 10:38 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,121

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
just a comment, probably a bug, probably not. In my environment the date-time printed is 27/05/15 10:48:32 for all the commands executed before that export HISTTIMEFORMAT= settings.
 
Old 05-27-2015, 10:41 AM   #6
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
Hi pan64,

Thanks for your reply.

Sorry didn't get your comment.

1)
Is it a prob in my environment?
Or
2)
is it something wrong with my HISTTIMEFORMAT?
Or
3)
There's something wrong with HISTTIMEFORMAT over all?

Quote:
Originally Posted by pan64 View Post
just a comment, probably a bug, probably not. In my environment the date-time printed is 27/05/15 10:48:32 for all the commands executed before that export HISTTIMEFORMAT= settings.
 
Old 05-27-2015, 10:43 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,121

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
no, it means the saving of execution time did not work before... (or something similar)
 
Old 05-27-2015, 10:49 AM   #8
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
I see.
Thank you.
Quote:
Originally Posted by pan64 View Post
no, it means the saving of execution time did not work before... (or something similar)
 
  


Reply

Tags
bash, history


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] What to do after I ran scrot command AlexBB Linux - Newbie 2 03-08-2014 09:27 PM
File size varies with same 'ls -lh' command ran on two different versions of Redhat visitashu Red Hat 6 10-27-2010 01:58 AM
Running a command as another user in a bash script ran as root? camphor Programming 2 03-29-2009 04:11 PM
I ran this command /etc/rc.d/init.d/iptables stop and after this unable to browse muasif80 Linux - Newbie 2 10-05-2008 01:21 PM
date command aetucker1 Linux - General 3 01-21-2005 01:57 PM


All times are GMT -5. The time now is 12:22 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration