Is there any way to check history only of current session?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
9
down vote

favorite
1












I wanted to know if there is any command or any other way I can check my command history only in the current session.







share|improve this question


























    up vote
    9
    down vote

    favorite
    1












    I wanted to know if there is any command or any other way I can check my command history only in the current session.







    share|improve this question
























      up vote
      9
      down vote

      favorite
      1









      up vote
      9
      down vote

      favorite
      1






      1





      I wanted to know if there is any command or any other way I can check my command history only in the current session.







      share|improve this question














      I wanted to know if there is any command or any other way I can check my command history only in the current session.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 21 at 17:38









      Zanna

      48k13119227




      48k13119227










      asked Apr 21 at 17:22









      Andrew

      1824




      1824




















          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.






          share|improve this answer






















            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',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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.






            share|improve this answer


























              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.






              share|improve this answer
























                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.






                share|improve this answer














                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.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 22 at 7:02

























                answered Apr 21 at 17:25









                Sergiy Kolodyazhnyy

                64.9k9129282




                64.9k9129282



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    pylint3 and pip3 broken

                    Missing snmpget and snmpwalk

                    How to enroll fingerprints to Ubuntu 17.10 with VFS491