How can I save a part of command lines into a new file using history command?Bash history handling with multiple terminalsBash command history not workingBash history search, partial + up-arrowHistory list without timestamp and unique the resultshow do I remove the last 5 lines in bash history?Excluding some commands from getting stored in bash history only after terminal is closedHow can I get the total size of .conf extension in directory /etc and save them into another file?How to run a command in loop on pairs of files that share only the initial part of the filename

A single word for "not allowed to be changed" or "must be this way"

Is it academically dishonest to submit the same project to two different classes in the same semester?

Simplify & Reduce steps in the IsDistinct function

Is a triangle waveform a type of pulse width modulation?

What does 36.000€ mean?

Centered text and Equations aligned

Can the Detect Magic spell detect an Antimagic Field spell?

How can I get a ride in the jump seat as a non-professional pilot?

Eligibility vector for softmax policy with policy gradients

Retracting Recommendation Letters

Is publishing runnable code instead of pseudo code shunned?

Keep password in macro?

How can I order rows returned by the RETURNING clause of a DML statement?

Who verifies the trust of certificate authorities?

Next Shared Totient

Found that newly hired employee wasn't completely frank. What would be good to do in that situation?

Template not provided using create-react-app

Did the Windows 95 screensavers use hardware acceleration APIs?

Evil plans - how do you come up with interesting ones?

Thoughts on using user stories to define business/platform needs?

Permanent river of lava

Do Adventure cards count towards "number of instant and sorcery cards in your graveyard"?

Can I re-whip whipped cream?

Brake disc and pads corrosion, do they need replacement?



How can I save a part of command lines into a new file using history command?


Bash history handling with multiple terminalsBash command history not workingBash history search, partial + up-arrowHistory list without timestamp and unique the resultshow do I remove the last 5 lines in bash history?Excluding some commands from getting stored in bash history only after terminal is closedHow can I get the total size of .conf extension in directory /etc and save them into another file?How to run a command in loop on pairs of files that share only the initial part of the filename






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4


















I am a beginner of bash.
I know that type



history


can show all command lines and .bash_history save all of them. But if I want a part of command lines (e.g., current session) and save them into a new file, what should I do? I checked



history --help


and still, do not understand how to do so.
Thanks for help in advance!










share|improve this question































    4


















    I am a beginner of bash.
    I know that type



    history


    can show all command lines and .bash_history save all of them. But if I want a part of command lines (e.g., current session) and save them into a new file, what should I do? I checked



    history --help


    and still, do not understand how to do so.
    Thanks for help in advance!










    share|improve this question



























      4













      4









      4








      I am a beginner of bash.
      I know that type



      history


      can show all command lines and .bash_history save all of them. But if I want a part of command lines (e.g., current session) and save them into a new file, what should I do? I checked



      history --help


      and still, do not understand how to do so.
      Thanks for help in advance!










      share|improve this question














      I am a beginner of bash.
      I know that type



      history


      can show all command lines and .bash_history save all of them. But if I want a part of command lines (e.g., current session) and save them into a new file, what should I do? I checked



      history --help


      and still, do not understand how to do so.
      Thanks for help in advance!







      command-line bash






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 21 at 22:30









      SRMZSRMZ

      411 bronze badge




      411 bronze badge























          4 Answers
          4






          active

          oldest

          votes


















          1



















          Current session:



          You can do so by running the following command in the terminal:



          history -a ~/current_session.txt


          Current session's history will be saved to a file named current_session.txt in your home directory.




          Certain inputs:



          You can also search all history for a certain input and save the output to a file. For example to save all lines that have install in them, please run the following command in the terminal:



          history | grep install > ~/search_results.txt


          Search results will be saved to a file named search_results.txt in your home directory.




          Change install to whatever you want to search for.



          To search for multiple inputs put them between two quotation marks
          "" , separate them with a pipe | and put -E before them like so:



          history | grep -E "install|update|upgrade" > ~/search_results.txt




          Best of luck






          share|improve this answer


































            1



















            You need to use -a together with a file name. As explained in help history:




            history: history [-c] [-d offset] [n] or history -anrw [filename] or
            history -ps arg [arg...]



            (...)



            -a append history lines from this session to the history file




            And later on:




            If FILENAME is given, it is used as the history file. Otherwise, if
            $HISTFILE has a value, that is used, else ~/.bash_history.




            For example, start a new session and type this ($ is a prompt, it will most probably be different on your system):



            $ echo a-new-session started at $(date)
            $ history -a /tmp/new-history


            In this case /tmp/new-history will be:



            echo a-new-session started at $(date)
            history -a /tmp/new-history





            share|improve this answer


































              0



















              an inferior answer but it works,



              type history to get the history.
              mouse swipe want you want to copy
              ctrl-shift-c to copy
              and ctrl-v to paste into a text editor.



              in my case, terminal was konsole and text editor was kate.



              this lets you copy and paste selected parts of the history.



              also lets you copy and paste into the terminal from history , crtl-shift-v to paste






              share|improve this answer
































                0



















                You could skip the above answers by putting the bash history in a seperate, per-session file to begin with.



                See my answer Bash history handling with multiple terminals






                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',
                  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
                  );



                  );














                  draft saved

                  draft discarded
















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1175757%2fhow-can-i-save-a-part-of-command-lines-into-a-new-file-using-history-command%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown


























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  1



















                  Current session:



                  You can do so by running the following command in the terminal:



                  history -a ~/current_session.txt


                  Current session's history will be saved to a file named current_session.txt in your home directory.




                  Certain inputs:



                  You can also search all history for a certain input and save the output to a file. For example to save all lines that have install in them, please run the following command in the terminal:



                  history | grep install > ~/search_results.txt


                  Search results will be saved to a file named search_results.txt in your home directory.




                  Change install to whatever you want to search for.



                  To search for multiple inputs put them between two quotation marks
                  "" , separate them with a pipe | and put -E before them like so:



                  history | grep -E "install|update|upgrade" > ~/search_results.txt




                  Best of luck






                  share|improve this answer































                    1



















                    Current session:



                    You can do so by running the following command in the terminal:



                    history -a ~/current_session.txt


                    Current session's history will be saved to a file named current_session.txt in your home directory.




                    Certain inputs:



                    You can also search all history for a certain input and save the output to a file. For example to save all lines that have install in them, please run the following command in the terminal:



                    history | grep install > ~/search_results.txt


                    Search results will be saved to a file named search_results.txt in your home directory.




                    Change install to whatever you want to search for.



                    To search for multiple inputs put them between two quotation marks
                    "" , separate them with a pipe | and put -E before them like so:



                    history | grep -E "install|update|upgrade" > ~/search_results.txt




                    Best of luck






                    share|improve this answer





























                      1















                      1











                      1









                      Current session:



                      You can do so by running the following command in the terminal:



                      history -a ~/current_session.txt


                      Current session's history will be saved to a file named current_session.txt in your home directory.




                      Certain inputs:



                      You can also search all history for a certain input and save the output to a file. For example to save all lines that have install in them, please run the following command in the terminal:



                      history | grep install > ~/search_results.txt


                      Search results will be saved to a file named search_results.txt in your home directory.




                      Change install to whatever you want to search for.



                      To search for multiple inputs put them between two quotation marks
                      "" , separate them with a pipe | and put -E before them like so:



                      history | grep -E "install|update|upgrade" > ~/search_results.txt




                      Best of luck






                      share|improve this answer
















                      Current session:



                      You can do so by running the following command in the terminal:



                      history -a ~/current_session.txt


                      Current session's history will be saved to a file named current_session.txt in your home directory.




                      Certain inputs:



                      You can also search all history for a certain input and save the output to a file. For example to save all lines that have install in them, please run the following command in the terminal:



                      history | grep install > ~/search_results.txt


                      Search results will be saved to a file named search_results.txt in your home directory.




                      Change install to whatever you want to search for.



                      To search for multiple inputs put them between two quotation marks
                      "" , separate them with a pipe | and put -E before them like so:



                      history | grep -E "install|update|upgrade" > ~/search_results.txt




                      Best of luck







                      share|improve this answer















                      share|improve this answer




                      share|improve this answer








                      edited Sep 21 at 23:29

























                      answered Sep 21 at 22:38









                      RaffaRaffa

                      1,9721 gold badge4 silver badges17 bronze badges




                      1,9721 gold badge4 silver badges17 bronze badges


























                          1



















                          You need to use -a together with a file name. As explained in help history:




                          history: history [-c] [-d offset] [n] or history -anrw [filename] or
                          history -ps arg [arg...]



                          (...)



                          -a append history lines from this session to the history file




                          And later on:




                          If FILENAME is given, it is used as the history file. Otherwise, if
                          $HISTFILE has a value, that is used, else ~/.bash_history.




                          For example, start a new session and type this ($ is a prompt, it will most probably be different on your system):



                          $ echo a-new-session started at $(date)
                          $ history -a /tmp/new-history


                          In this case /tmp/new-history will be:



                          echo a-new-session started at $(date)
                          history -a /tmp/new-history





                          share|improve this answer































                            1



















                            You need to use -a together with a file name. As explained in help history:




                            history: history [-c] [-d offset] [n] or history -anrw [filename] or
                            history -ps arg [arg...]



                            (...)



                            -a append history lines from this session to the history file




                            And later on:




                            If FILENAME is given, it is used as the history file. Otherwise, if
                            $HISTFILE has a value, that is used, else ~/.bash_history.




                            For example, start a new session and type this ($ is a prompt, it will most probably be different on your system):



                            $ echo a-new-session started at $(date)
                            $ history -a /tmp/new-history


                            In this case /tmp/new-history will be:



                            echo a-new-session started at $(date)
                            history -a /tmp/new-history





                            share|improve this answer





























                              1















                              1











                              1









                              You need to use -a together with a file name. As explained in help history:




                              history: history [-c] [-d offset] [n] or history -anrw [filename] or
                              history -ps arg [arg...]



                              (...)



                              -a append history lines from this session to the history file




                              And later on:




                              If FILENAME is given, it is used as the history file. Otherwise, if
                              $HISTFILE has a value, that is used, else ~/.bash_history.




                              For example, start a new session and type this ($ is a prompt, it will most probably be different on your system):



                              $ echo a-new-session started at $(date)
                              $ history -a /tmp/new-history


                              In this case /tmp/new-history will be:



                              echo a-new-session started at $(date)
                              history -a /tmp/new-history





                              share|improve this answer
















                              You need to use -a together with a file name. As explained in help history:




                              history: history [-c] [-d offset] [n] or history -anrw [filename] or
                              history -ps arg [arg...]



                              (...)



                              -a append history lines from this session to the history file




                              And later on:




                              If FILENAME is given, it is used as the history file. Otherwise, if
                              $HISTFILE has a value, that is used, else ~/.bash_history.




                              For example, start a new session and type this ($ is a prompt, it will most probably be different on your system):



                              $ echo a-new-session started at $(date)
                              $ history -a /tmp/new-history


                              In this case /tmp/new-history will be:



                              echo a-new-session started at $(date)
                              history -a /tmp/new-history






                              share|improve this answer















                              share|improve this answer




                              share|improve this answer








                              edited Sep 27 at 20:17

























                              answered Sep 21 at 22:38









                              Arkadiusz DrabczykArkadiusz Drabczyk

                              1,2335 silver badges12 bronze badges




                              1,2335 silver badges12 bronze badges
























                                  0



















                                  an inferior answer but it works,



                                  type history to get the history.
                                  mouse swipe want you want to copy
                                  ctrl-shift-c to copy
                                  and ctrl-v to paste into a text editor.



                                  in my case, terminal was konsole and text editor was kate.



                                  this lets you copy and paste selected parts of the history.



                                  also lets you copy and paste into the terminal from history , crtl-shift-v to paste






                                  share|improve this answer





























                                    0



















                                    an inferior answer but it works,



                                    type history to get the history.
                                    mouse swipe want you want to copy
                                    ctrl-shift-c to copy
                                    and ctrl-v to paste into a text editor.



                                    in my case, terminal was konsole and text editor was kate.



                                    this lets you copy and paste selected parts of the history.



                                    also lets you copy and paste into the terminal from history , crtl-shift-v to paste






                                    share|improve this answer



























                                      0















                                      0











                                      0









                                      an inferior answer but it works,



                                      type history to get the history.
                                      mouse swipe want you want to copy
                                      ctrl-shift-c to copy
                                      and ctrl-v to paste into a text editor.



                                      in my case, terminal was konsole and text editor was kate.



                                      this lets you copy and paste selected parts of the history.



                                      also lets you copy and paste into the terminal from history , crtl-shift-v to paste






                                      share|improve this answer














                                      an inferior answer but it works,



                                      type history to get the history.
                                      mouse swipe want you want to copy
                                      ctrl-shift-c to copy
                                      and ctrl-v to paste into a text editor.



                                      in my case, terminal was konsole and text editor was kate.



                                      this lets you copy and paste selected parts of the history.



                                      also lets you copy and paste into the terminal from history , crtl-shift-v to paste







                                      share|improve this answer













                                      share|improve this answer




                                      share|improve this answer










                                      answered Sep 22 at 2:58









                                      pierrelypierrely

                                      1415 bronze badges




                                      1415 bronze badges
























                                          0



















                                          You could skip the above answers by putting the bash history in a seperate, per-session file to begin with.



                                          See my answer Bash history handling with multiple terminals






                                          share|improve this answer





























                                            0



















                                            You could skip the above answers by putting the bash history in a seperate, per-session file to begin with.



                                            See my answer Bash history handling with multiple terminals






                                            share|improve this answer



























                                              0















                                              0











                                              0









                                              You could skip the above answers by putting the bash history in a seperate, per-session file to begin with.



                                              See my answer Bash history handling with multiple terminals






                                              share|improve this answer














                                              You could skip the above answers by putting the bash history in a seperate, per-session file to begin with.



                                              See my answer Bash history handling with multiple terminals







                                              share|improve this answer













                                              share|improve this answer




                                              share|improve this answer










                                              answered Sep 22 at 3:36









                                              waltinatorwaltinator

                                              25.6k7 gold badges43 silver badges74 bronze badges




                                              25.6k7 gold badges43 silver badges74 bronze badges































                                                  draft saved

                                                  draft discarded















































                                                  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.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1175757%2fhow-can-i-save-a-part-of-command-lines-into-a-new-file-using-history-command%23new-answer', 'question_page');

                                                  );

                                                  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









                                                  Popular posts from this blog

                                                  Tamil (spriik) Luke uk diar | Nawigatjuun

                                                  Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                                  Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?