How to remove command-line history from a specific time period?
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
3
down vote
favorite
How can I remove command-line history over a specific time period?
Is it possible do so with only one command?
command-line bash history
add a comment |Â
up vote
3
down vote
favorite
How can I remove command-line history over a specific time period?
Is it possible do so with only one command?
command-line bash history
Are you just trying to ensure that someone after you cannot see what you have done?
â Charles Green
Dec 12 '15 at 20:52
Basically, yes.
â TellMeWhy
Dec 12 '15 at 20:53
I just edit ~/.bash_history and delete the lines I don't want left around.
â Doug Smythies
Dec 12 '15 at 20:54
2
prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
â Charles Green
Dec 12 '15 at 20:57
2
The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
â Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
How can I remove command-line history over a specific time period?
Is it possible do so with only one command?
command-line bash history
How can I remove command-line history over a specific time period?
Is it possible do so with only one command?
command-line bash history
command-line bash history
edited Dec 12 '15 at 21:32
muru
130k19275470
130k19275470
asked Dec 12 '15 at 20:46
![](https://i.stack.imgur.com/8QhKP.jpg?s=32&g=1)
![](https://i.stack.imgur.com/8QhKP.jpg?s=32&g=1)
TellMeWhy
7,4461661114
7,4461661114
Are you just trying to ensure that someone after you cannot see what you have done?
â Charles Green
Dec 12 '15 at 20:52
Basically, yes.
â TellMeWhy
Dec 12 '15 at 20:53
I just edit ~/.bash_history and delete the lines I don't want left around.
â Doug Smythies
Dec 12 '15 at 20:54
2
prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
â Charles Green
Dec 12 '15 at 20:57
2
The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
â Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59
add a comment |Â
Are you just trying to ensure that someone after you cannot see what you have done?
â Charles Green
Dec 12 '15 at 20:52
Basically, yes.
â TellMeWhy
Dec 12 '15 at 20:53
I just edit ~/.bash_history and delete the lines I don't want left around.
â Doug Smythies
Dec 12 '15 at 20:54
2
prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
â Charles Green
Dec 12 '15 at 20:57
2
The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
â Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59
Are you just trying to ensure that someone after you cannot see what you have done?
â Charles Green
Dec 12 '15 at 20:52
Are you just trying to ensure that someone after you cannot see what you have done?
â Charles Green
Dec 12 '15 at 20:52
Basically, yes.
â TellMeWhy
Dec 12 '15 at 20:53
Basically, yes.
â TellMeWhy
Dec 12 '15 at 20:53
I just edit ~/.bash_history and delete the lines I don't want left around.
â Doug Smythies
Dec 12 '15 at 20:54
I just edit ~/.bash_history and delete the lines I don't want left around.
â Doug Smythies
Dec 12 '15 at 20:54
2
2
prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
â Charles Green
Dec 12 '15 at 20:57
prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
â Charles Green
Dec 12 '15 at 20:57
2
2
The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
â Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59
The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
â Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT
in man bash
:
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a
format string for strftime(3) to print the time stamp associated
with each history entry displayed by the history builtin. If
this variable is set, time stamps are written to the history
file so they may be preserved across shell sessions. This uses
the history comment character to distinguish timestamps from
other history lines.
If you had set HISTTIMEFORMAT
before you ran the commands you wanted to delete, your .bash_history
would have lines like so:
$ tail -4 ~/.bash_history
#1449955320
history
#1449955329
history -w
Then you could take advantage of the Unix timestamps to delete them, using awk
, for example:
awk -F# -v end=$(date -d yesterday +%s)
-v start=$(date -d 'now - 3 days' +%s)
'$2 < start || $2 > end print; getline; print'
I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history
to delete it.
If you hadn't set HISTTIMEFORMAT
beforehand, then you'll have to do this manually.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT
in man bash
:
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a
format string for strftime(3) to print the time stamp associated
with each history entry displayed by the history builtin. If
this variable is set, time stamps are written to the history
file so they may be preserved across shell sessions. This uses
the history comment character to distinguish timestamps from
other history lines.
If you had set HISTTIMEFORMAT
before you ran the commands you wanted to delete, your .bash_history
would have lines like so:
$ tail -4 ~/.bash_history
#1449955320
history
#1449955329
history -w
Then you could take advantage of the Unix timestamps to delete them, using awk
, for example:
awk -F# -v end=$(date -d yesterday +%s)
-v start=$(date -d 'now - 3 days' +%s)
'$2 < start || $2 > end print; getline; print'
I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history
to delete it.
If you hadn't set HISTTIMEFORMAT
beforehand, then you'll have to do this manually.
add a comment |Â
up vote
3
down vote
accepted
While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT
in man bash
:
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a
format string for strftime(3) to print the time stamp associated
with each history entry displayed by the history builtin. If
this variable is set, time stamps are written to the history
file so they may be preserved across shell sessions. This uses
the history comment character to distinguish timestamps from
other history lines.
If you had set HISTTIMEFORMAT
before you ran the commands you wanted to delete, your .bash_history
would have lines like so:
$ tail -4 ~/.bash_history
#1449955320
history
#1449955329
history -w
Then you could take advantage of the Unix timestamps to delete them, using awk
, for example:
awk -F# -v end=$(date -d yesterday +%s)
-v start=$(date -d 'now - 3 days' +%s)
'$2 < start || $2 > end print; getline; print'
I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history
to delete it.
If you hadn't set HISTTIMEFORMAT
beforehand, then you'll have to do this manually.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT
in man bash
:
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a
format string for strftime(3) to print the time stamp associated
with each history entry displayed by the history builtin. If
this variable is set, time stamps are written to the history
file so they may be preserved across shell sessions. This uses
the history comment character to distinguish timestamps from
other history lines.
If you had set HISTTIMEFORMAT
before you ran the commands you wanted to delete, your .bash_history
would have lines like so:
$ tail -4 ~/.bash_history
#1449955320
history
#1449955329
history -w
Then you could take advantage of the Unix timestamps to delete them, using awk
, for example:
awk -F# -v end=$(date -d yesterday +%s)
-v start=$(date -d 'now - 3 days' +%s)
'$2 < start || $2 > end print; getline; print'
I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history
to delete it.
If you hadn't set HISTTIMEFORMAT
beforehand, then you'll have to do this manually.
While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT
in man bash
:
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a
format string for strftime(3) to print the time stamp associated
with each history entry displayed by the history builtin. If
this variable is set, time stamps are written to the history
file so they may be preserved across shell sessions. This uses
the history comment character to distinguish timestamps from
other history lines.
If you had set HISTTIMEFORMAT
before you ran the commands you wanted to delete, your .bash_history
would have lines like so:
$ tail -4 ~/.bash_history
#1449955320
history
#1449955329
history -w
Then you could take advantage of the Unix timestamps to delete them, using awk
, for example:
awk -F# -v end=$(date -d yesterday +%s)
-v start=$(date -d 'now - 3 days' +%s)
'$2 < start || $2 > end print; getline; print'
I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history
to delete it.
If you hadn't set HISTTIMEFORMAT
beforehand, then you'll have to do this manually.
answered Dec 12 '15 at 21:29
muru
130k19275470
130k19275470
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f708906%2fhow-to-remove-command-line-history-from-a-specific-time-period%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
Are you just trying to ensure that someone after you cannot see what you have done?
â Charles Green
Dec 12 '15 at 20:52
Basically, yes.
â TellMeWhy
Dec 12 '15 at 20:53
I just edit ~/.bash_history and delete the lines I don't want left around.
â Doug Smythies
Dec 12 '15 at 20:54
2
prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
â Charles Green
Dec 12 '15 at 20:57
2
The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
â Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59