Is there any way to check history only of current session?
up vote
9
down vote
favorite
I wanted to know if there is any command or any other way I can check my command history only in the current session.
command-line history
add a comment |Â
up vote
9
down vote
favorite
I wanted to know if there is any command or any other way I can check my command history only in the current session.
command-line history
add a comment |Â
up vote
9
down vote
favorite
up vote
9
down vote
favorite
I wanted to know if there is any command or any other way I can check my command history only in the current session.
command-line history
I wanted to know if there is any command or any other way I can check my command history only in the current session.
command-line history
edited Apr 21 at 17:38
Zanna
48k13119227
48k13119227
asked Apr 21 at 17:22
Andrew
1824
1824
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
12
down vote
accepted
The history
built in bash
allows specifying filenames when used with -anrw
flags, and -a
flag description from help history
states:
append history lines from this session to the history file
Therefore, we can do:
~$ history -a this_session.history
~$ cat ./this_session.history
history mysession.history
cat mysession.history
clear
history -a this_session.history
For the record, -w
(the write history to file opion) writes whole history to the specified file, so -a
(append) here is preferred choice.
There's other manual ways. In particular ksh
doesn't have -a
flag as bash
does, but what ksh
and mksh
do have is HISTFILE
environment variable ( and bash
has that,too, because bash
included lots of ksh
features); by the way, this variable by default isn't set (at least mksh
on Ubuntu didn't set it). So, for outputting current session to other file, we call HISTFILE
prepended to command which in shell syntax means running command with additional environment variable you specify. Like so:
bash-4.4$ HISTFILE='mykshfile.hist' ksh
$ echo 'Hello'
Hello
$ echo 'World'
World
$
bash-4.4$ cat ./mykshfile.hist
�echo 'Hello'
echo 'World'
What you also can see from this is that ksh
and its related shells output history with special characters, instead of plain text as what bash
does. So, you may want to open that file with ksh
.
As far as the POSIX /bin/sh
shell on Ubuntu, which is Debian Almquist Shell or Dash, there exists fc
built-in. However, on Ubuntu dash is compiled without lib-edit, which is a conscious choice by Ubuntu developers for performance reasons, so fc
and other modes that require line editing don't work out of the box (unless recompile dash
yourself and install lib-edit
).
Shell neutral ways would be to record your session with existing tools or write your own function to record on per-command basis.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
12
down vote
accepted
The history
built in bash
allows specifying filenames when used with -anrw
flags, and -a
flag description from help history
states:
append history lines from this session to the history file
Therefore, we can do:
~$ history -a this_session.history
~$ cat ./this_session.history
history mysession.history
cat mysession.history
clear
history -a this_session.history
For the record, -w
(the write history to file opion) writes whole history to the specified file, so -a
(append) here is preferred choice.
There's other manual ways. In particular ksh
doesn't have -a
flag as bash
does, but what ksh
and mksh
do have is HISTFILE
environment variable ( and bash
has that,too, because bash
included lots of ksh
features); by the way, this variable by default isn't set (at least mksh
on Ubuntu didn't set it). So, for outputting current session to other file, we call HISTFILE
prepended to command which in shell syntax means running command with additional environment variable you specify. Like so:
bash-4.4$ HISTFILE='mykshfile.hist' ksh
$ echo 'Hello'
Hello
$ echo 'World'
World
$
bash-4.4$ cat ./mykshfile.hist
�echo 'Hello'
echo 'World'
What you also can see from this is that ksh
and its related shells output history with special characters, instead of plain text as what bash
does. So, you may want to open that file with ksh
.
As far as the POSIX /bin/sh
shell on Ubuntu, which is Debian Almquist Shell or Dash, there exists fc
built-in. However, on Ubuntu dash is compiled without lib-edit, which is a conscious choice by Ubuntu developers for performance reasons, so fc
and other modes that require line editing don't work out of the box (unless recompile dash
yourself and install lib-edit
).
Shell neutral ways would be to record your session with existing tools or write your own function to record on per-command basis.
add a comment |Â
up vote
12
down vote
accepted
The history
built in bash
allows specifying filenames when used with -anrw
flags, and -a
flag description from help history
states:
append history lines from this session to the history file
Therefore, we can do:
~$ history -a this_session.history
~$ cat ./this_session.history
history mysession.history
cat mysession.history
clear
history -a this_session.history
For the record, -w
(the write history to file opion) writes whole history to the specified file, so -a
(append) here is preferred choice.
There's other manual ways. In particular ksh
doesn't have -a
flag as bash
does, but what ksh
and mksh
do have is HISTFILE
environment variable ( and bash
has that,too, because bash
included lots of ksh
features); by the way, this variable by default isn't set (at least mksh
on Ubuntu didn't set it). So, for outputting current session to other file, we call HISTFILE
prepended to command which in shell syntax means running command with additional environment variable you specify. Like so:
bash-4.4$ HISTFILE='mykshfile.hist' ksh
$ echo 'Hello'
Hello
$ echo 'World'
World
$
bash-4.4$ cat ./mykshfile.hist
�echo 'Hello'
echo 'World'
What you also can see from this is that ksh
and its related shells output history with special characters, instead of plain text as what bash
does. So, you may want to open that file with ksh
.
As far as the POSIX /bin/sh
shell on Ubuntu, which is Debian Almquist Shell or Dash, there exists fc
built-in. However, on Ubuntu dash is compiled without lib-edit, which is a conscious choice by Ubuntu developers for performance reasons, so fc
and other modes that require line editing don't work out of the box (unless recompile dash
yourself and install lib-edit
).
Shell neutral ways would be to record your session with existing tools or write your own function to record on per-command basis.
add a comment |Â
up vote
12
down vote
accepted
up vote
12
down vote
accepted
The history
built in bash
allows specifying filenames when used with -anrw
flags, and -a
flag description from help history
states:
append history lines from this session to the history file
Therefore, we can do:
~$ history -a this_session.history
~$ cat ./this_session.history
history mysession.history
cat mysession.history
clear
history -a this_session.history
For the record, -w
(the write history to file opion) writes whole history to the specified file, so -a
(append) here is preferred choice.
There's other manual ways. In particular ksh
doesn't have -a
flag as bash
does, but what ksh
and mksh
do have is HISTFILE
environment variable ( and bash
has that,too, because bash
included lots of ksh
features); by the way, this variable by default isn't set (at least mksh
on Ubuntu didn't set it). So, for outputting current session to other file, we call HISTFILE
prepended to command which in shell syntax means running command with additional environment variable you specify. Like so:
bash-4.4$ HISTFILE='mykshfile.hist' ksh
$ echo 'Hello'
Hello
$ echo 'World'
World
$
bash-4.4$ cat ./mykshfile.hist
�echo 'Hello'
echo 'World'
What you also can see from this is that ksh
and its related shells output history with special characters, instead of plain text as what bash
does. So, you may want to open that file with ksh
.
As far as the POSIX /bin/sh
shell on Ubuntu, which is Debian Almquist Shell or Dash, there exists fc
built-in. However, on Ubuntu dash is compiled without lib-edit, which is a conscious choice by Ubuntu developers for performance reasons, so fc
and other modes that require line editing don't work out of the box (unless recompile dash
yourself and install lib-edit
).
Shell neutral ways would be to record your session with existing tools or write your own function to record on per-command basis.
The history
built in bash
allows specifying filenames when used with -anrw
flags, and -a
flag description from help history
states:
append history lines from this session to the history file
Therefore, we can do:
~$ history -a this_session.history
~$ cat ./this_session.history
history mysession.history
cat mysession.history
clear
history -a this_session.history
For the record, -w
(the write history to file opion) writes whole history to the specified file, so -a
(append) here is preferred choice.
There's other manual ways. In particular ksh
doesn't have -a
flag as bash
does, but what ksh
and mksh
do have is HISTFILE
environment variable ( and bash
has that,too, because bash
included lots of ksh
features); by the way, this variable by default isn't set (at least mksh
on Ubuntu didn't set it). So, for outputting current session to other file, we call HISTFILE
prepended to command which in shell syntax means running command with additional environment variable you specify. Like so:
bash-4.4$ HISTFILE='mykshfile.hist' ksh
$ echo 'Hello'
Hello
$ echo 'World'
World
$
bash-4.4$ cat ./mykshfile.hist
�echo 'Hello'
echo 'World'
What you also can see from this is that ksh
and its related shells output history with special characters, instead of plain text as what bash
does. So, you may want to open that file with ksh
.
As far as the POSIX /bin/sh
shell on Ubuntu, which is Debian Almquist Shell or Dash, there exists fc
built-in. However, on Ubuntu dash is compiled without lib-edit, which is a conscious choice by Ubuntu developers for performance reasons, so fc
and other modes that require line editing don't work out of the box (unless recompile dash
yourself and install lib-edit
).
Shell neutral ways would be to record your session with existing tools or write your own function to record on per-command basis.
edited Apr 22 at 7:02
answered Apr 21 at 17:25
Sergiy Kolodyazhnyy
64.9k9129282
64.9k9129282
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%2f1026997%2fis-there-any-way-to-check-history-only-of-current-session%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