How to see time stamps in bash history?How to know the time of execution of previous commandsRecord date when command was executed in the terminal?What do the numbers mean in output of history?Terminal command for getting information about the time and user of all the commands executed in all sessions of terminalBash history handling with multiple terminalsHow to clear bash history completely?How to delete selected results from bash history?Bash History not containing all history and blank after reboot, how to resolve?Get bash history to remember only the commands run with space prefixed!How do I make Bash history undeleteable?How to save terminal history to a file from a bash file?Half of bash history is missingCan I get the commands from history executed in bash in the last 15 mins?
Length-terminated sequences
If equal temperament divides an octave into 12 equal parts, why are the hertz differences not the same but 12ths of two?
Why do the Romance languages use definite articles, when Latin doesn't?
Should I use muryou or tada 無料 or 只?
Java IntStream iterate vs generate when to use what?
Is rent considered a debt?
Is there an unambiguous name for the social/political theory "liberalism" without "leftist"?
I love fishing, dancing, playing, crafting, and fighting
should I include offer letter from a different institution in my application for a faculty position
Duality in mixed integer linear programs
How much damage should a creature take if it runs across lava while wearing a Ring of Water Walking?
Is this really played by 2200+ players?
Why didn't Petunia know that Harry wasn't supposed to use magic out of school?
Is maximizing hamming distance the same as minimizing correlation?
Is there any physical evidence for motion?
What's the origin of the trope that dragons used to be common but aren't any more?
Endless disc brake issues
Heat-shrink tubing available as a roll like adhesive tape?
Is 写真 an onomatopoeia?
Is it plausible for a certain area of a continent to be/remain/become uninhabited for a long period of time?
You see a boat filled with people
Do you still need a Test Plan when adopting Continuous Delivery?
Googlebot crawls my page too often
What are the limits of religious freedom in the workplace?
How to see time stamps in bash history?
How to know the time of execution of previous commandsRecord date when command was executed in the terminal?What do the numbers mean in output of history?Terminal command for getting information about the time and user of all the commands executed in all sessions of terminalBash history handling with multiple terminalsHow to clear bash history completely?How to delete selected results from bash history?Bash History not containing all history and blank after reboot, how to resolve?Get bash history to remember only the commands run with space prefixed!How do I make Bash history undeleteable?How to save terminal history to a file from a bash file?Half of bash history is missingCan I get the commands from history executed in bash in the last 15 mins?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?
Bottom-Line: Execution time in the Bash history
command-line bash history
add a comment
|
Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?
Bottom-Line: Execution time in the Bash history
command-line bash history
7
I'm amazed how poorly documented this is both on Linux and BSD in the manpages.
– Sridhar Sarnobat
Aug 30 '16 at 21:52
Check this blog out - sanctum.geek.nz/arabesque/better-bash-history .
– abhicantdraw
Feb 22 '18 at 10:31
4
if you're using zsh:history -E
– Vahid
Nov 6 '18 at 16:58
4
Not sure why two answers below feel the need to tell you how to open a terminal..
– mwfearnley
Dec 24 '18 at 8:39
2
According to the blog referenced by @dog0 , timestampse apparently do not get saved unless theHISTTIMEFORMAT
variable was set when commands were issued. In other words, if you didn't have it set, setting it now will not help you retrieve timestamps of previously issued commands.
– Tomislav Nakic-Alfirevic
Jan 17 at 15:14
add a comment
|
Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?
Bottom-Line: Execution time in the Bash history
command-line bash history
Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?
Bottom-Line: Execution time in the Bash history
command-line bash history
command-line bash history
edited Jun 22 '15 at 8:13
7ochem
1741 gold badge3 silver badges13 bronze badges
1741 gold badge3 silver badges13 bronze badges
asked Dec 15 '13 at 11:58
rɑːdʒɑrɑːdʒɑ
62.7k88 gold badges223 silver badges307 bronze badges
62.7k88 gold badges223 silver badges307 bronze badges
7
I'm amazed how poorly documented this is both on Linux and BSD in the manpages.
– Sridhar Sarnobat
Aug 30 '16 at 21:52
Check this blog out - sanctum.geek.nz/arabesque/better-bash-history .
– abhicantdraw
Feb 22 '18 at 10:31
4
if you're using zsh:history -E
– Vahid
Nov 6 '18 at 16:58
4
Not sure why two answers below feel the need to tell you how to open a terminal..
– mwfearnley
Dec 24 '18 at 8:39
2
According to the blog referenced by @dog0 , timestampse apparently do not get saved unless theHISTTIMEFORMAT
variable was set when commands were issued. In other words, if you didn't have it set, setting it now will not help you retrieve timestamps of previously issued commands.
– Tomislav Nakic-Alfirevic
Jan 17 at 15:14
add a comment
|
7
I'm amazed how poorly documented this is both on Linux and BSD in the manpages.
– Sridhar Sarnobat
Aug 30 '16 at 21:52
Check this blog out - sanctum.geek.nz/arabesque/better-bash-history .
– abhicantdraw
Feb 22 '18 at 10:31
4
if you're using zsh:history -E
– Vahid
Nov 6 '18 at 16:58
4
Not sure why two answers below feel the need to tell you how to open a terminal..
– mwfearnley
Dec 24 '18 at 8:39
2
According to the blog referenced by @dog0 , timestampse apparently do not get saved unless theHISTTIMEFORMAT
variable was set when commands were issued. In other words, if you didn't have it set, setting it now will not help you retrieve timestamps of previously issued commands.
– Tomislav Nakic-Alfirevic
Jan 17 at 15:14
7
7
I'm amazed how poorly documented this is both on Linux and BSD in the manpages.
– Sridhar Sarnobat
Aug 30 '16 at 21:52
I'm amazed how poorly documented this is both on Linux and BSD in the manpages.
– Sridhar Sarnobat
Aug 30 '16 at 21:52
Check this blog out - sanctum.geek.nz/arabesque/better-bash-history .
– abhicantdraw
Feb 22 '18 at 10:31
Check this blog out - sanctum.geek.nz/arabesque/better-bash-history .
– abhicantdraw
Feb 22 '18 at 10:31
4
4
if you're using zsh:
history -E
– Vahid
Nov 6 '18 at 16:58
if you're using zsh:
history -E
– Vahid
Nov 6 '18 at 16:58
4
4
Not sure why two answers below feel the need to tell you how to open a terminal..
– mwfearnley
Dec 24 '18 at 8:39
Not sure why two answers below feel the need to tell you how to open a terminal..
– mwfearnley
Dec 24 '18 at 8:39
2
2
According to the blog referenced by @dog0 , timestampse apparently do not get saved unless the
HISTTIMEFORMAT
variable was set when commands were issued. In other words, if you didn't have it set, setting it now will not help you retrieve timestamps of previously issued commands.– Tomislav Nakic-Alfirevic
Jan 17 at 15:14
According to the blog referenced by @dog0 , timestampse apparently do not get saved unless the
HISTTIMEFORMAT
variable was set when commands were issued. In other words, if you didn't have it set, setting it now will not help you retrieve timestamps of previously issued commands.– Tomislav Nakic-Alfirevic
Jan 17 at 15:14
add a comment
|
6 Answers
6
active
oldest
votes
Press Ctrl+Alt+T to open Terminal, then run the command below:
HISTTIMEFORMAT="%d/%m/%y %T "
Or, to make the change permanent for the current user:
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc
Then
history
For more info see man bash or An A-Z Index of the Bash command line for Linux.
For commands that were run before HISTTIMEFORMAT
was set, the current time will be saved as the timestamp. Commands run after HISTTIMEFORMAT
was set will have the proper timestamp saved.
7
Why declare it withexport
in.bash_profile
? It is a variable only read bybash
, not by commands launched from it, so it should not be exported.
– Alvaro Gutierrez Perez
Oct 19 '15 at 21:36
71
Note that this will only record timestamps for new history items, afterHISTTIMEFORMAT
is set for sessions, i.e. you can't use this retrospectively. Some answers here give the impression the history command immediately shows timestamped entries
– Louis Maddox
Feb 20 '16 at 20:58
10
@Louis - Actually this worked for me retroactively for me?!?!
– stephenmm
Mar 29 '16 at 15:24
19
@Jamil: for people who follow ISO standards, it's "%y-%m-%d" for the date part ;)
– Gauthier
Mar 31 '16 at 11:03
13
@Gauthier - actually, just use %F for ISO date ;-) man7.org/linux/man-pages/man3/strftime.3.html
– brianmearns
Jul 11 '18 at 19:34
|
show 12 more comments
Open terminalCtrl+Alt+T and run,
HISTTIMEFORMAT="%d/%m/%y %T "
then,
history
To make the changes permanent follow the below steps,
gedit ~/.bashrc
you need to add the below line to .bashrc file and then save it,
export HISTTIMEFORMAT="%d/%m/%y %T "
run the below command to source .bashrc file,
source ~/.bashrc
After that run history
command.
source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
Thanks for answering , will it be permanent change ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
1
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc?
– LasagnaAndroid
Oct 1 '15 at 17:28
add a comment
|
Yes, you can: if you set $HISTTIMEFORMAT
, the .bash-history
will be properly timestamped. That doesn't help with existing .bash-history
content, but will help in the future.
1
can you expand it for more clarity ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
5
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :)
– user491029
Jan 8 '16 at 22:43
4
I set $HISTTIMEFORMAT and I got the times for today even before the commands of this set.
– Yasin Okumuş
Sep 18 '17 at 13:40
@user491029 "...even existing". This is true, but misleading. On ubuntu 14.04, at least, it did start showing timestamps for all history entries once I had set HISTTIMEFORMAT, but it looks like the timestamps for any command run before the current session were the login timestamp of the current session.
– jbobbins
Jun 27 at 19:52
add a comment
|
You'll see changes on next login.
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
add a comment
|
To enable history timestamps for all users, create a script in /etc/profile.d :
echo 'HISTTIMEFORMAT="%Y%m%d %T "' >> /etc/profile.d/timestamp.sh
1
This will likely not work for users logging in via the GUI, since the default terminal will not run login shells./etc/bash.bashrc
would be a better place.
– muru
Feb 22 '18 at 10:12
add a comment
|
I know, I'm answering it very late, but to do this for all the users, you can create any .sh
file in /etc/profile.d
and add the following line to it:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' >> /etc/profile.d/existing-foo-file.sh
If you not logged in as root
or superuser, you need to use the tee
command to do this:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee /etc/profile.d/mytimestamp.sh
If you want to append to any existing file, pass -a
flag to tee
command:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee -a /etc/profile.d/mytimestamp.sh
Hello Shashank, Thanks for adding the answer but how this answer is different from others ? If your answer is completely different then we are glad to have it, but if not you can improve existing answers.
– rɑːdʒɑ
Jul 22 at 5:03
Hi, thanks for commenting. This is different from others in the following way: 1. Some of them have mentioned about creating for all users but no one mentioned about creating/explaining any file name in/etc/profile.d
.timestamp.sh
looks very close to technical (so it creates confusion) so I used the nameexisting-foo-file.sh
(foo-bar concept). 2. No one has mentioned about using it with non-root users. So I have given an example of usingsudo
. 3. The 3rd example improves the 2nd example of appending to an existing file. Since linux/unix beginners can hit this issue, I elaborated.
– Shashank Agrawal
Jul 22 at 5:32
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f391082%2fhow-to-see-time-stamps-in-bash-history%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Press Ctrl+Alt+T to open Terminal, then run the command below:
HISTTIMEFORMAT="%d/%m/%y %T "
Or, to make the change permanent for the current user:
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc
Then
history
For more info see man bash or An A-Z Index of the Bash command line for Linux.
For commands that were run before HISTTIMEFORMAT
was set, the current time will be saved as the timestamp. Commands run after HISTTIMEFORMAT
was set will have the proper timestamp saved.
7
Why declare it withexport
in.bash_profile
? It is a variable only read bybash
, not by commands launched from it, so it should not be exported.
– Alvaro Gutierrez Perez
Oct 19 '15 at 21:36
71
Note that this will only record timestamps for new history items, afterHISTTIMEFORMAT
is set for sessions, i.e. you can't use this retrospectively. Some answers here give the impression the history command immediately shows timestamped entries
– Louis Maddox
Feb 20 '16 at 20:58
10
@Louis - Actually this worked for me retroactively for me?!?!
– stephenmm
Mar 29 '16 at 15:24
19
@Jamil: for people who follow ISO standards, it's "%y-%m-%d" for the date part ;)
– Gauthier
Mar 31 '16 at 11:03
13
@Gauthier - actually, just use %F for ISO date ;-) man7.org/linux/man-pages/man3/strftime.3.html
– brianmearns
Jul 11 '18 at 19:34
|
show 12 more comments
Press Ctrl+Alt+T to open Terminal, then run the command below:
HISTTIMEFORMAT="%d/%m/%y %T "
Or, to make the change permanent for the current user:
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc
Then
history
For more info see man bash or An A-Z Index of the Bash command line for Linux.
For commands that were run before HISTTIMEFORMAT
was set, the current time will be saved as the timestamp. Commands run after HISTTIMEFORMAT
was set will have the proper timestamp saved.
7
Why declare it withexport
in.bash_profile
? It is a variable only read bybash
, not by commands launched from it, so it should not be exported.
– Alvaro Gutierrez Perez
Oct 19 '15 at 21:36
71
Note that this will only record timestamps for new history items, afterHISTTIMEFORMAT
is set for sessions, i.e. you can't use this retrospectively. Some answers here give the impression the history command immediately shows timestamped entries
– Louis Maddox
Feb 20 '16 at 20:58
10
@Louis - Actually this worked for me retroactively for me?!?!
– stephenmm
Mar 29 '16 at 15:24
19
@Jamil: for people who follow ISO standards, it's "%y-%m-%d" for the date part ;)
– Gauthier
Mar 31 '16 at 11:03
13
@Gauthier - actually, just use %F for ISO date ;-) man7.org/linux/man-pages/man3/strftime.3.html
– brianmearns
Jul 11 '18 at 19:34
|
show 12 more comments
Press Ctrl+Alt+T to open Terminal, then run the command below:
HISTTIMEFORMAT="%d/%m/%y %T "
Or, to make the change permanent for the current user:
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc
Then
history
For more info see man bash or An A-Z Index of the Bash command line for Linux.
For commands that were run before HISTTIMEFORMAT
was set, the current time will be saved as the timestamp. Commands run after HISTTIMEFORMAT
was set will have the proper timestamp saved.
Press Ctrl+Alt+T to open Terminal, then run the command below:
HISTTIMEFORMAT="%d/%m/%y %T "
Or, to make the change permanent for the current user:
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc
Then
history
For more info see man bash or An A-Z Index of the Bash command line for Linux.
For commands that were run before HISTTIMEFORMAT
was set, the current time will be saved as the timestamp. Commands run after HISTTIMEFORMAT
was set will have the proper timestamp saved.
edited Aug 5 at 16:45
Community♦
1
1
answered Dec 15 '13 at 12:03
Mitch♦Mitch
89.2k15 gold badges182 silver badges241 bronze badges
89.2k15 gold badges182 silver badges241 bronze badges
7
Why declare it withexport
in.bash_profile
? It is a variable only read bybash
, not by commands launched from it, so it should not be exported.
– Alvaro Gutierrez Perez
Oct 19 '15 at 21:36
71
Note that this will only record timestamps for new history items, afterHISTTIMEFORMAT
is set for sessions, i.e. you can't use this retrospectively. Some answers here give the impression the history command immediately shows timestamped entries
– Louis Maddox
Feb 20 '16 at 20:58
10
@Louis - Actually this worked for me retroactively for me?!?!
– stephenmm
Mar 29 '16 at 15:24
19
@Jamil: for people who follow ISO standards, it's "%y-%m-%d" for the date part ;)
– Gauthier
Mar 31 '16 at 11:03
13
@Gauthier - actually, just use %F for ISO date ;-) man7.org/linux/man-pages/man3/strftime.3.html
– brianmearns
Jul 11 '18 at 19:34
|
show 12 more comments
7
Why declare it withexport
in.bash_profile
? It is a variable only read bybash
, not by commands launched from it, so it should not be exported.
– Alvaro Gutierrez Perez
Oct 19 '15 at 21:36
71
Note that this will only record timestamps for new history items, afterHISTTIMEFORMAT
is set for sessions, i.e. you can't use this retrospectively. Some answers here give the impression the history command immediately shows timestamped entries
– Louis Maddox
Feb 20 '16 at 20:58
10
@Louis - Actually this worked for me retroactively for me?!?!
– stephenmm
Mar 29 '16 at 15:24
19
@Jamil: for people who follow ISO standards, it's "%y-%m-%d" for the date part ;)
– Gauthier
Mar 31 '16 at 11:03
13
@Gauthier - actually, just use %F for ISO date ;-) man7.org/linux/man-pages/man3/strftime.3.html
– brianmearns
Jul 11 '18 at 19:34
7
7
Why declare it with
export
in .bash_profile
? It is a variable only read by bash
, not by commands launched from it, so it should not be exported.– Alvaro Gutierrez Perez
Oct 19 '15 at 21:36
Why declare it with
export
in .bash_profile
? It is a variable only read by bash
, not by commands launched from it, so it should not be exported.– Alvaro Gutierrez Perez
Oct 19 '15 at 21:36
71
71
Note that this will only record timestamps for new history items, after
HISTTIMEFORMAT
is set for sessions, i.e. you can't use this retrospectively. Some answers here give the impression the history command immediately shows timestamped entries– Louis Maddox
Feb 20 '16 at 20:58
Note that this will only record timestamps for new history items, after
HISTTIMEFORMAT
is set for sessions, i.e. you can't use this retrospectively. Some answers here give the impression the history command immediately shows timestamped entries– Louis Maddox
Feb 20 '16 at 20:58
10
10
@Louis - Actually this worked for me retroactively for me?!?!
– stephenmm
Mar 29 '16 at 15:24
@Louis - Actually this worked for me retroactively for me?!?!
– stephenmm
Mar 29 '16 at 15:24
19
19
@Jamil: for people who follow ISO standards, it's "%y-%m-%d" for the date part ;)
– Gauthier
Mar 31 '16 at 11:03
@Jamil: for people who follow ISO standards, it's "%y-%m-%d" for the date part ;)
– Gauthier
Mar 31 '16 at 11:03
13
13
@Gauthier - actually, just use %F for ISO date ;-) man7.org/linux/man-pages/man3/strftime.3.html
– brianmearns
Jul 11 '18 at 19:34
@Gauthier - actually, just use %F for ISO date ;-) man7.org/linux/man-pages/man3/strftime.3.html
– brianmearns
Jul 11 '18 at 19:34
|
show 12 more comments
Open terminalCtrl+Alt+T and run,
HISTTIMEFORMAT="%d/%m/%y %T "
then,
history
To make the changes permanent follow the below steps,
gedit ~/.bashrc
you need to add the below line to .bashrc file and then save it,
export HISTTIMEFORMAT="%d/%m/%y %T "
run the below command to source .bashrc file,
source ~/.bashrc
After that run history
command.
source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
Thanks for answering , will it be permanent change ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
1
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc?
– LasagnaAndroid
Oct 1 '15 at 17:28
add a comment
|
Open terminalCtrl+Alt+T and run,
HISTTIMEFORMAT="%d/%m/%y %T "
then,
history
To make the changes permanent follow the below steps,
gedit ~/.bashrc
you need to add the below line to .bashrc file and then save it,
export HISTTIMEFORMAT="%d/%m/%y %T "
run the below command to source .bashrc file,
source ~/.bashrc
After that run history
command.
source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
Thanks for answering , will it be permanent change ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
1
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc?
– LasagnaAndroid
Oct 1 '15 at 17:28
add a comment
|
Open terminalCtrl+Alt+T and run,
HISTTIMEFORMAT="%d/%m/%y %T "
then,
history
To make the changes permanent follow the below steps,
gedit ~/.bashrc
you need to add the below line to .bashrc file and then save it,
export HISTTIMEFORMAT="%d/%m/%y %T "
run the below command to source .bashrc file,
source ~/.bashrc
After that run history
command.
source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
Open terminalCtrl+Alt+T and run,
HISTTIMEFORMAT="%d/%m/%y %T "
then,
history
To make the changes permanent follow the below steps,
gedit ~/.bashrc
you need to add the below line to .bashrc file and then save it,
export HISTTIMEFORMAT="%d/%m/%y %T "
run the below command to source .bashrc file,
source ~/.bashrc
After that run history
command.
source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
edited Dec 16 '13 at 2:25
Seth♦
37.9k28 gold badges121 silver badges179 bronze badges
37.9k28 gold badges121 silver badges179 bronze badges
answered Dec 15 '13 at 12:02
Avinash RajAvinash Raj
55.7k44 gold badges178 silver badges228 bronze badges
55.7k44 gold badges178 silver badges228 bronze badges
Thanks for answering , will it be permanent change ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
1
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc?
– LasagnaAndroid
Oct 1 '15 at 17:28
add a comment
|
Thanks for answering , will it be permanent change ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
1
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc?
– LasagnaAndroid
Oct 1 '15 at 17:28
Thanks for answering , will it be permanent change ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
Thanks for answering , will it be permanent change ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
1
1
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc?
– LasagnaAndroid
Oct 1 '15 at 17:28
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc?
– LasagnaAndroid
Oct 1 '15 at 17:28
add a comment
|
Yes, you can: if you set $HISTTIMEFORMAT
, the .bash-history
will be properly timestamped. That doesn't help with existing .bash-history
content, but will help in the future.
1
can you expand it for more clarity ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
5
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :)
– user491029
Jan 8 '16 at 22:43
4
I set $HISTTIMEFORMAT and I got the times for today even before the commands of this set.
– Yasin Okumuş
Sep 18 '17 at 13:40
@user491029 "...even existing". This is true, but misleading. On ubuntu 14.04, at least, it did start showing timestamps for all history entries once I had set HISTTIMEFORMAT, but it looks like the timestamps for any command run before the current session were the login timestamp of the current session.
– jbobbins
Jun 27 at 19:52
add a comment
|
Yes, you can: if you set $HISTTIMEFORMAT
, the .bash-history
will be properly timestamped. That doesn't help with existing .bash-history
content, but will help in the future.
1
can you expand it for more clarity ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
5
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :)
– user491029
Jan 8 '16 at 22:43
4
I set $HISTTIMEFORMAT and I got the times for today even before the commands of this set.
– Yasin Okumuş
Sep 18 '17 at 13:40
@user491029 "...even existing". This is true, but misleading. On ubuntu 14.04, at least, it did start showing timestamps for all history entries once I had set HISTTIMEFORMAT, but it looks like the timestamps for any command run before the current session were the login timestamp of the current session.
– jbobbins
Jun 27 at 19:52
add a comment
|
Yes, you can: if you set $HISTTIMEFORMAT
, the .bash-history
will be properly timestamped. That doesn't help with existing .bash-history
content, but will help in the future.
Yes, you can: if you set $HISTTIMEFORMAT
, the .bash-history
will be properly timestamped. That doesn't help with existing .bash-history
content, but will help in the future.
answered Dec 15 '13 at 12:02
Dennis KaarsemakerDennis Kaarsemaker
6,01418 silver badges36 bronze badges
6,01418 silver badges36 bronze badges
1
can you expand it for more clarity ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
5
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :)
– user491029
Jan 8 '16 at 22:43
4
I set $HISTTIMEFORMAT and I got the times for today even before the commands of this set.
– Yasin Okumuş
Sep 18 '17 at 13:40
@user491029 "...even existing". This is true, but misleading. On ubuntu 14.04, at least, it did start showing timestamps for all history entries once I had set HISTTIMEFORMAT, but it looks like the timestamps for any command run before the current session were the login timestamp of the current session.
– jbobbins
Jun 27 at 19:52
add a comment
|
1
can you expand it for more clarity ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
5
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :)
– user491029
Jan 8 '16 at 22:43
4
I set $HISTTIMEFORMAT and I got the times for today even before the commands of this set.
– Yasin Okumuş
Sep 18 '17 at 13:40
@user491029 "...even existing". This is true, but misleading. On ubuntu 14.04, at least, it did start showing timestamps for all history entries once I had set HISTTIMEFORMAT, but it looks like the timestamps for any command run before the current session were the login timestamp of the current session.
– jbobbins
Jun 27 at 19:52
1
1
can you expand it for more clarity ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
can you expand it for more clarity ?
– rɑːdʒɑ
Dec 15 '13 at 12:06
5
5
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :)
– user491029
Jan 8 '16 at 22:43
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :)
– user491029
Jan 8 '16 at 22:43
4
4
I set $HISTTIMEFORMAT and I got the times for today even before the commands of this set.
– Yasin Okumuş
Sep 18 '17 at 13:40
I set $HISTTIMEFORMAT and I got the times for today even before the commands of this set.
– Yasin Okumuş
Sep 18 '17 at 13:40
@user491029 "...even existing". This is true, but misleading. On ubuntu 14.04, at least, it did start showing timestamps for all history entries once I had set HISTTIMEFORMAT, but it looks like the timestamps for any command run before the current session were the login timestamp of the current session.
– jbobbins
Jun 27 at 19:52
@user491029 "...even existing". This is true, but misleading. On ubuntu 14.04, at least, it did start showing timestamps for all history entries once I had set HISTTIMEFORMAT, but it looks like the timestamps for any command run before the current session were the login timestamp of the current session.
– jbobbins
Jun 27 at 19:52
add a comment
|
You'll see changes on next login.
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
add a comment
|
You'll see changes on next login.
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
add a comment
|
You'll see changes on next login.
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
You'll see changes on next login.
echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
edited May 29 at 10:58
Kulfy
8,21310 gold badges32 silver badges60 bronze badges
8,21310 gold badges32 silver badges60 bronze badges
answered May 29 at 8:14
DimiDakDimiDak
2082 silver badges7 bronze badges
2082 silver badges7 bronze badges
add a comment
|
add a comment
|
To enable history timestamps for all users, create a script in /etc/profile.d :
echo 'HISTTIMEFORMAT="%Y%m%d %T "' >> /etc/profile.d/timestamp.sh
1
This will likely not work for users logging in via the GUI, since the default terminal will not run login shells./etc/bash.bashrc
would be a better place.
– muru
Feb 22 '18 at 10:12
add a comment
|
To enable history timestamps for all users, create a script in /etc/profile.d :
echo 'HISTTIMEFORMAT="%Y%m%d %T "' >> /etc/profile.d/timestamp.sh
1
This will likely not work for users logging in via the GUI, since the default terminal will not run login shells./etc/bash.bashrc
would be a better place.
– muru
Feb 22 '18 at 10:12
add a comment
|
To enable history timestamps for all users, create a script in /etc/profile.d :
echo 'HISTTIMEFORMAT="%Y%m%d %T "' >> /etc/profile.d/timestamp.sh
To enable history timestamps for all users, create a script in /etc/profile.d :
echo 'HISTTIMEFORMAT="%Y%m%d %T "' >> /etc/profile.d/timestamp.sh
answered Jan 9 '18 at 21:18
iiiiii
1172 bronze badges
1172 bronze badges
1
This will likely not work for users logging in via the GUI, since the default terminal will not run login shells./etc/bash.bashrc
would be a better place.
– muru
Feb 22 '18 at 10:12
add a comment
|
1
This will likely not work for users logging in via the GUI, since the default terminal will not run login shells./etc/bash.bashrc
would be a better place.
– muru
Feb 22 '18 at 10:12
1
1
This will likely not work for users logging in via the GUI, since the default terminal will not run login shells.
/etc/bash.bashrc
would be a better place.– muru
Feb 22 '18 at 10:12
This will likely not work for users logging in via the GUI, since the default terminal will not run login shells.
/etc/bash.bashrc
would be a better place.– muru
Feb 22 '18 at 10:12
add a comment
|
I know, I'm answering it very late, but to do this for all the users, you can create any .sh
file in /etc/profile.d
and add the following line to it:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' >> /etc/profile.d/existing-foo-file.sh
If you not logged in as root
or superuser, you need to use the tee
command to do this:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee /etc/profile.d/mytimestamp.sh
If you want to append to any existing file, pass -a
flag to tee
command:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee -a /etc/profile.d/mytimestamp.sh
Hello Shashank, Thanks for adding the answer but how this answer is different from others ? If your answer is completely different then we are glad to have it, but if not you can improve existing answers.
– rɑːdʒɑ
Jul 22 at 5:03
Hi, thanks for commenting. This is different from others in the following way: 1. Some of them have mentioned about creating for all users but no one mentioned about creating/explaining any file name in/etc/profile.d
.timestamp.sh
looks very close to technical (so it creates confusion) so I used the nameexisting-foo-file.sh
(foo-bar concept). 2. No one has mentioned about using it with non-root users. So I have given an example of usingsudo
. 3. The 3rd example improves the 2nd example of appending to an existing file. Since linux/unix beginners can hit this issue, I elaborated.
– Shashank Agrawal
Jul 22 at 5:32
add a comment
|
I know, I'm answering it very late, but to do this for all the users, you can create any .sh
file in /etc/profile.d
and add the following line to it:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' >> /etc/profile.d/existing-foo-file.sh
If you not logged in as root
or superuser, you need to use the tee
command to do this:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee /etc/profile.d/mytimestamp.sh
If you want to append to any existing file, pass -a
flag to tee
command:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee -a /etc/profile.d/mytimestamp.sh
Hello Shashank, Thanks for adding the answer but how this answer is different from others ? If your answer is completely different then we are glad to have it, but if not you can improve existing answers.
– rɑːdʒɑ
Jul 22 at 5:03
Hi, thanks for commenting. This is different from others in the following way: 1. Some of them have mentioned about creating for all users but no one mentioned about creating/explaining any file name in/etc/profile.d
.timestamp.sh
looks very close to technical (so it creates confusion) so I used the nameexisting-foo-file.sh
(foo-bar concept). 2. No one has mentioned about using it with non-root users. So I have given an example of usingsudo
. 3. The 3rd example improves the 2nd example of appending to an existing file. Since linux/unix beginners can hit this issue, I elaborated.
– Shashank Agrawal
Jul 22 at 5:32
add a comment
|
I know, I'm answering it very late, but to do this for all the users, you can create any .sh
file in /etc/profile.d
and add the following line to it:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' >> /etc/profile.d/existing-foo-file.sh
If you not logged in as root
or superuser, you need to use the tee
command to do this:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee /etc/profile.d/mytimestamp.sh
If you want to append to any existing file, pass -a
flag to tee
command:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee -a /etc/profile.d/mytimestamp.sh
I know, I'm answering it very late, but to do this for all the users, you can create any .sh
file in /etc/profile.d
and add the following line to it:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' >> /etc/profile.d/existing-foo-file.sh
If you not logged in as root
or superuser, you need to use the tee
command to do this:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee /etc/profile.d/mytimestamp.sh
If you want to append to any existing file, pass -a
flag to tee
command:
echo 'HISTTIMEFORMAT="%Y-%m-%d %T "' | sudo tee -a /etc/profile.d/mytimestamp.sh
answered Jul 20 at 10:40
Shashank AgrawalShashank Agrawal
1093 bronze badges
1093 bronze badges
Hello Shashank, Thanks for adding the answer but how this answer is different from others ? If your answer is completely different then we are glad to have it, but if not you can improve existing answers.
– rɑːdʒɑ
Jul 22 at 5:03
Hi, thanks for commenting. This is different from others in the following way: 1. Some of them have mentioned about creating for all users but no one mentioned about creating/explaining any file name in/etc/profile.d
.timestamp.sh
looks very close to technical (so it creates confusion) so I used the nameexisting-foo-file.sh
(foo-bar concept). 2. No one has mentioned about using it with non-root users. So I have given an example of usingsudo
. 3. The 3rd example improves the 2nd example of appending to an existing file. Since linux/unix beginners can hit this issue, I elaborated.
– Shashank Agrawal
Jul 22 at 5:32
add a comment
|
Hello Shashank, Thanks for adding the answer but how this answer is different from others ? If your answer is completely different then we are glad to have it, but if not you can improve existing answers.
– rɑːdʒɑ
Jul 22 at 5:03
Hi, thanks for commenting. This is different from others in the following way: 1. Some of them have mentioned about creating for all users but no one mentioned about creating/explaining any file name in/etc/profile.d
.timestamp.sh
looks very close to technical (so it creates confusion) so I used the nameexisting-foo-file.sh
(foo-bar concept). 2. No one has mentioned about using it with non-root users. So I have given an example of usingsudo
. 3. The 3rd example improves the 2nd example of appending to an existing file. Since linux/unix beginners can hit this issue, I elaborated.
– Shashank Agrawal
Jul 22 at 5:32
Hello Shashank, Thanks for adding the answer but how this answer is different from others ? If your answer is completely different then we are glad to have it, but if not you can improve existing answers.
– rɑːdʒɑ
Jul 22 at 5:03
Hello Shashank, Thanks for adding the answer but how this answer is different from others ? If your answer is completely different then we are glad to have it, but if not you can improve existing answers.
– rɑːdʒɑ
Jul 22 at 5:03
Hi, thanks for commenting. This is different from others in the following way: 1. Some of them have mentioned about creating for all users but no one mentioned about creating/explaining any file name in
/etc/profile.d
. timestamp.sh
looks very close to technical (so it creates confusion) so I used the name existing-foo-file.sh
(foo-bar concept). 2. No one has mentioned about using it with non-root users. So I have given an example of using sudo
. 3. The 3rd example improves the 2nd example of appending to an existing file. Since linux/unix beginners can hit this issue, I elaborated.– Shashank Agrawal
Jul 22 at 5:32
Hi, thanks for commenting. This is different from others in the following way: 1. Some of them have mentioned about creating for all users but no one mentioned about creating/explaining any file name in
/etc/profile.d
. timestamp.sh
looks very close to technical (so it creates confusion) so I used the name existing-foo-file.sh
(foo-bar concept). 2. No one has mentioned about using it with non-root users. So I have given an example of using sudo
. 3. The 3rd example improves the 2nd example of appending to an existing file. Since linux/unix beginners can hit this issue, I elaborated.– Shashank Agrawal
Jul 22 at 5:32
add a comment
|
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f391082%2fhow-to-see-time-stamps-in-bash-history%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
7
I'm amazed how poorly documented this is both on Linux and BSD in the manpages.
– Sridhar Sarnobat
Aug 30 '16 at 21:52
Check this blog out - sanctum.geek.nz/arabesque/better-bash-history .
– abhicantdraw
Feb 22 '18 at 10:31
4
if you're using zsh:
history -E
– Vahid
Nov 6 '18 at 16:58
4
Not sure why two answers below feel the need to tell you how to open a terminal..
– mwfearnley
Dec 24 '18 at 8:39
2
According to the blog referenced by @dog0 , timestampse apparently do not get saved unless the
HISTTIMEFORMAT
variable was set when commands were issued. In other words, if you didn't have it set, setting it now will not help you retrieve timestamps of previously issued commands.– Tomislav Nakic-Alfirevic
Jan 17 at 15:14