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;
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
add a comment
|
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
add a comment
|
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
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
command-line bash
asked Sep 21 at 22:30
SRMZSRMZ
411 bronze badge
411 bronze badge
add a comment
|
add a comment
|
4 Answers
4
active
oldest
votes
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
add a comment
|
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
add a comment
|
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
add a comment
|
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
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%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
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
add a comment
|
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
add a comment
|
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
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
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
add a comment
|
add a comment
|
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
add a comment
|
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
add a comment
|
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
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
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
add a comment
|
add a comment
|
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
add a comment
|
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
add a comment
|
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
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
answered Sep 22 at 2:58
pierrelypierrely
1415 bronze badges
1415 bronze badges
add a comment
|
add a comment
|
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
add a comment
|
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
add a comment
|
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
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
answered Sep 22 at 3:36
waltinatorwaltinator
25.6k7 gold badges43 silver badges74 bronze badges
25.6k7 gold badges43 silver badges74 bronze badges
add a comment
|
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%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
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