How to delete selected results from bash history?
history
command shows all the results but we can filter to get particular command using history | grep searchingCommand
. It is really helpful.
But the problem is it shows those commands also which was entered with typo error or which was unsuccessful. Then identifying the correct one is really a pain. I checked this link: Selective command-history in the terminal? but that was not my solution.
So is there a way to delete those commands from the history which was incorrect at the time entered or later?
bash
add a comment |
history
command shows all the results but we can filter to get particular command using history | grep searchingCommand
. It is really helpful.
But the problem is it shows those commands also which was entered with typo error or which was unsuccessful. Then identifying the correct one is really a pain. I checked this link: Selective command-history in the terminal? but that was not my solution.
So is there a way to delete those commands from the history which was incorrect at the time entered or later?
bash
5
Please, change the accepted answer, there are other with more that 100 up votes.
– greuze
Sep 27 '17 at 14:20
1
@greuze: Changed to the best answer. Count of votes doesn't mean that it's the best!
– Saurav Kumar
Apr 20 '18 at 13:09
add a comment |
history
command shows all the results but we can filter to get particular command using history | grep searchingCommand
. It is really helpful.
But the problem is it shows those commands also which was entered with typo error or which was unsuccessful. Then identifying the correct one is really a pain. I checked this link: Selective command-history in the terminal? but that was not my solution.
So is there a way to delete those commands from the history which was incorrect at the time entered or later?
bash
history
command shows all the results but we can filter to get particular command using history | grep searchingCommand
. It is really helpful.
But the problem is it shows those commands also which was entered with typo error or which was unsuccessful. Then identifying the correct one is really a pain. I checked this link: Selective command-history in the terminal? but that was not my solution.
So is there a way to delete those commands from the history which was incorrect at the time entered or later?
bash
bash
edited Apr 13 '17 at 12:25
Community♦
1
1
asked Sep 12 '13 at 9:28
Saurav KumarSaurav Kumar
10.5k134665
10.5k134665
5
Please, change the accepted answer, there are other with more that 100 up votes.
– greuze
Sep 27 '17 at 14:20
1
@greuze: Changed to the best answer. Count of votes doesn't mean that it's the best!
– Saurav Kumar
Apr 20 '18 at 13:09
add a comment |
5
Please, change the accepted answer, there are other with more that 100 up votes.
– greuze
Sep 27 '17 at 14:20
1
@greuze: Changed to the best answer. Count of votes doesn't mean that it's the best!
– Saurav Kumar
Apr 20 '18 at 13:09
5
5
Please, change the accepted answer, there are other with more that 100 up votes.
– greuze
Sep 27 '17 at 14:20
Please, change the accepted answer, there are other with more that 100 up votes.
– greuze
Sep 27 '17 at 14:20
1
1
@greuze: Changed to the best answer. Count of votes doesn't mean that it's the best!
– Saurav Kumar
Apr 20 '18 at 13:09
@greuze: Changed to the best answer. Count of votes doesn't mean that it's the best!
– Saurav Kumar
Apr 20 '18 at 13:09
add a comment |
7 Answers
7
active
oldest
votes
I'd like to add another method of modifying (or deleting) history entries, which I found rather accidentally when I was working with the bash:
To demonstrate this, start by executing the following three commands in bash:
$ echo 1
1
$ echo 2
2
$ echo 3
3
You can now select these commands again using the arrow keys or Ctrl+p and Ctrl+n.
Say you want to modify the first two commands. Move through history until echo 1
appears and change it to echo 1 - changed
, but DO NOT PRESS ENTER. If you now move further through your history, this line stays in its modified state and you can move away from and back to it. Now move to the line echo 2
and change it to echo 2 - changed
, again don't press enter. In order to save the changes to these lines, select any command in history except for these two, and hit Ctrl+c.
Of course, instead of modifying the history entry, you may also remove it which will result in an empty line at that entry. To delete the line currently displayed at the prompt, hit Ctrl+e (which jumps to the end of the line) followed by Ctrl+u (which deletes the text from the start of the line to the cursor).
See also https://unix.stackexchange.com/questions/195668/what-can-cause-an-item-to-be-deleted-from-my-bash-history/195726#195726 for a more detailed explanation of the technical background.
Simplest Way:
ctrl+r to search the command you want to delete/modify.
end to select the searched command to delete/modify- Delete or modify the selected command (don't press enter or ctrl + c)
up arrow(or ctrl+p) or down arrow(or ctrl+n) to select any other command.
ctrl+c That's it!
Note:
This changes only the current session commands. If we want to change older commands and save the changes we need to run following command before closing the terminal:
history -w
Many thanks Stefan! I must say that you brought an awesome things. Using this I found the most simplest way to modify/delete the history: 1.ctrl+r
to search the command you want to delete/modify. 2.end
to move the command and delete/modify the command. 3.ctrl+n
to go to next line and then 4.ctrl+c
– Saurav Kumar
Feb 1 '18 at 14:10
add a comment |
Use:
history -d OFFSET
to delete the history entry at offset OFFSET
even before it was added to your bash history file. To find out the right OFFSET
, you need only to run history
command. It's the number from from the start of the line which contain the history entry that you want to delete it.
And to save the modifications to the history use:
history -w
See more details in this guide.
not bad :) Good to get a new way..
– Saurav Kumar
Feb 27 '14 at 11:34
10
@SauravKumar Not bad?!? Probably is the best way...
– Radu Rădeanu
Mar 27 '14 at 17:04
5
READ FIRST: Just to be clear you must dohistory -w
afterwords to save the changes. Also OFFSET means which number thathistory
displays. If the line you are try to delete is 873 then usehistory -d 873
.
– Cammy_the_block
Aug 2 '14 at 16:07
2
@RaduRădeanu Usehistory -w
afterhistory -d
to save changes.
– Cammy_the_block
Aug 2 '14 at 16:09
20
This should be the correct answer.
– topher
Jun 3 '15 at 11:47
|
show 3 more comments
Edit the file ~/.bash_history
and delete the once with typos
For example, insert this command:
gedit ~/.bash_history
Edit something you like and after than save file and restart terminal.
The root command is:
sudo -i
inser your password
gedit ~/.bash_history
if you want to delete all history -c
should do the trick
SYNTAX
history
history [n]
history -c
history -d offset
history [-anrw] [filename]
history -ps arg
KEY
-c Clear the history list. This may be combined with
the other options to replace the history list completely.
-d offset
Delete the history entry at position offset.
offset should be specified as it appears when the history is displayed.
-a Append the new history lines (history lines entered since
the beginning of the current Bash session) to the history file.
-n Append the history lines not already read from the history
file
to the current history list. These are lines appended to the
history file since the beginning of the current Bash session.
-r Read the current history file and append its contents to the
history list.
-w Write out the current history to the history file.
-p Perform history substitution on the args and display the
result
on the standard output, without storing the results in the history list.
-s The args are added to the end of the history list as a single
entry.
source:
- history Man Page | Bash | SS64.com
Thanks it is helpful! Do you know how to delete the entry at the time when entered from command line? Or is there any command to delete the entry without opening the.bash_history
?
– Saurav Kumar
Sep 12 '13 at 9:39
1
@bladed19899history -c
doesn't work When I close terminal and open it again histories are not deleted. -1 your answer
– αғsнιη
Jun 14 '14 at 20:56
1
@KasiyA,-c Clear the history list. This may be combined with the other options to replace the history list completely.
source
– blade19899
Jun 16 '14 at 8:44
2
@KasiyA Usehistory -w
afterhistory -c
to write the changes.
– Cammy_the_block
Aug 2 '14 at 16:10
add a comment |
If you want to immediately delete it form the same terminal first you have to add the following to your ~/.bashrc file.
PROMPT_COMMAND='history -a'
and restart your terminal.
You can add it anywhere in .bashrc file .I have added as below along with other history related stuff.
Usually during a bash session the executed commands are not written into .bash_history until the session is terminated hence PROMPT_COMMAND='history -a'
enters the command then and there into .bash_history.
Now whenever you make mistake or error in a command and want to delete it then and there just execute the following
sed -i '$d' ~/.bash_history
and tada it would be deleted.
To make it simpler you can alias it to something more simpler and use it such as
alias rh ='sed -i '''$d''' ~/.bash_history'
So executing rh
will remove the last executed command from history.
The above is temporary aliasing which only lasts for a session.To make it permanent or persistent add
alias rh = 'sed -i '''$d''' ~/.bash_history'
to .bashrc
NOTE
There should not be any space on both sides of =
If You Dont Want to Alias then You could also do the following
Make a commad name rh
and place it in /bin
directory:
Open a file say
rh
and paste following code, save and close:
sed -i '$d' ~/.bash_history
Make
rh
executable and place it in/bin
directory:
chmod +x rh
sudo cp rh /binNow use
rh
command to delete recent command from history.
Where to addPROMPT_COMMAND='history -a'
in.bashrc
file? And what exactly it will do? I triedsed -i '$d' ~/.bash_history
it's working without editing.bashrc
!! But alias thing is not working.. I will accept your answer if you just elaborate my question and make alias working.. :)
– Saurav Kumar
Sep 12 '13 at 15:15
@SauravKumar have edited the answer. Had missed the single and double quotes in aliasing command.. My bad.. :P
– Stormvirux
Sep 12 '13 at 16:29
Believe me or not.. alias thing is still not working.. It executes without any error but doesn't delete the entry from.bash_history
file.. :P any way.. Not a problem.. I made my own command and placed it in/bin
directory. Since because of your command:sed -i "$d" ~/.bash_history
it is working fine. I accept your answer.. :)
– Saurav Kumar
Sep 12 '13 at 16:48
If you don't mind, I would like to edit your answer so that it would be helpful to others..
– Saurav Kumar
Sep 12 '13 at 16:51
Actually I edited it. You've to approve it..
– Saurav Kumar
Sep 12 '13 at 17:27
|
show 2 more comments
If you are using "set -o vi" option in bash (very useful to search back with Escape key), then you can search for the line and delete the line with "dd" in the same way you do in "vi".
I find that I have to typej
ork
afterdd
to make it actually clear the command from history. If I type another command, or just pressEnter
, bash seems to assume it's just a new command and that it should retain the old command in history. It's also interesting to note that when it's done right, it clears the command, but doesn't delete it—the result is blank history entries. But this is good enough for removing passwords that I was forced to type at the command line, and much easier than other answers, so thanks very much for posting this!
– Michael Scheper
Jan 12 '18 at 0:30
add a comment |
to remove multiple lines (e.g. from 1974 to 1990, check with history
command):
for i in `seq 1974 1990` ; do history -d 1974 ; done
note that the line number to remove is always the same, as you are removing that one constantly and go to the next.
The note is very important.
– Weijun Zhou
Nov 24 '18 at 14:30
add a comment |
I had a situation where I had superfluous entries in my bash history from a Yubikey- maybe 50 or so, matching 'ccccc.....'. Ideally, I wanted a way to delete entries matching a pattern, which I suppose you could do with sed or something, assuming your history ignores blanks.
Anyway, I got lazy and ended up using vim, searching for 'cccc' and using 'dd' while cycling through every match. Didn't take more than a minute.
1
If you are doing this in vim then you could also do :g/cccc/d or :g/^cccc/d: or use a macro qqnddq then @@ (assumes your last search was for ccccc).
– htaccess
Jan 12 at 3:19
@htaccess That would certainly have been easier, but I kind of wanted to visually inspect the rest of the file at the same time.
– Dylan_Larkin
Jan 24 at 4:54
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/3.0/"u003ecc by-sa 3.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%2f344593%2fhow-to-delete-selected-results-from-bash-history%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'd like to add another method of modifying (or deleting) history entries, which I found rather accidentally when I was working with the bash:
To demonstrate this, start by executing the following three commands in bash:
$ echo 1
1
$ echo 2
2
$ echo 3
3
You can now select these commands again using the arrow keys or Ctrl+p and Ctrl+n.
Say you want to modify the first two commands. Move through history until echo 1
appears and change it to echo 1 - changed
, but DO NOT PRESS ENTER. If you now move further through your history, this line stays in its modified state and you can move away from and back to it. Now move to the line echo 2
and change it to echo 2 - changed
, again don't press enter. In order to save the changes to these lines, select any command in history except for these two, and hit Ctrl+c.
Of course, instead of modifying the history entry, you may also remove it which will result in an empty line at that entry. To delete the line currently displayed at the prompt, hit Ctrl+e (which jumps to the end of the line) followed by Ctrl+u (which deletes the text from the start of the line to the cursor).
See also https://unix.stackexchange.com/questions/195668/what-can-cause-an-item-to-be-deleted-from-my-bash-history/195726#195726 for a more detailed explanation of the technical background.
Simplest Way:
ctrl+r to search the command you want to delete/modify.
end to select the searched command to delete/modify- Delete or modify the selected command (don't press enter or ctrl + c)
up arrow(or ctrl+p) or down arrow(or ctrl+n) to select any other command.
ctrl+c That's it!
Note:
This changes only the current session commands. If we want to change older commands and save the changes we need to run following command before closing the terminal:
history -w
Many thanks Stefan! I must say that you brought an awesome things. Using this I found the most simplest way to modify/delete the history: 1.ctrl+r
to search the command you want to delete/modify. 2.end
to move the command and delete/modify the command. 3.ctrl+n
to go to next line and then 4.ctrl+c
– Saurav Kumar
Feb 1 '18 at 14:10
add a comment |
I'd like to add another method of modifying (or deleting) history entries, which I found rather accidentally when I was working with the bash:
To demonstrate this, start by executing the following three commands in bash:
$ echo 1
1
$ echo 2
2
$ echo 3
3
You can now select these commands again using the arrow keys or Ctrl+p and Ctrl+n.
Say you want to modify the first two commands. Move through history until echo 1
appears and change it to echo 1 - changed
, but DO NOT PRESS ENTER. If you now move further through your history, this line stays in its modified state and you can move away from and back to it. Now move to the line echo 2
and change it to echo 2 - changed
, again don't press enter. In order to save the changes to these lines, select any command in history except for these two, and hit Ctrl+c.
Of course, instead of modifying the history entry, you may also remove it which will result in an empty line at that entry. To delete the line currently displayed at the prompt, hit Ctrl+e (which jumps to the end of the line) followed by Ctrl+u (which deletes the text from the start of the line to the cursor).
See also https://unix.stackexchange.com/questions/195668/what-can-cause-an-item-to-be-deleted-from-my-bash-history/195726#195726 for a more detailed explanation of the technical background.
Simplest Way:
ctrl+r to search the command you want to delete/modify.
end to select the searched command to delete/modify- Delete or modify the selected command (don't press enter or ctrl + c)
up arrow(or ctrl+p) or down arrow(or ctrl+n) to select any other command.
ctrl+c That's it!
Note:
This changes only the current session commands. If we want to change older commands and save the changes we need to run following command before closing the terminal:
history -w
Many thanks Stefan! I must say that you brought an awesome things. Using this I found the most simplest way to modify/delete the history: 1.ctrl+r
to search the command you want to delete/modify. 2.end
to move the command and delete/modify the command. 3.ctrl+n
to go to next line and then 4.ctrl+c
– Saurav Kumar
Feb 1 '18 at 14:10
add a comment |
I'd like to add another method of modifying (or deleting) history entries, which I found rather accidentally when I was working with the bash:
To demonstrate this, start by executing the following three commands in bash:
$ echo 1
1
$ echo 2
2
$ echo 3
3
You can now select these commands again using the arrow keys or Ctrl+p and Ctrl+n.
Say you want to modify the first two commands. Move through history until echo 1
appears and change it to echo 1 - changed
, but DO NOT PRESS ENTER. If you now move further through your history, this line stays in its modified state and you can move away from and back to it. Now move to the line echo 2
and change it to echo 2 - changed
, again don't press enter. In order to save the changes to these lines, select any command in history except for these two, and hit Ctrl+c.
Of course, instead of modifying the history entry, you may also remove it which will result in an empty line at that entry. To delete the line currently displayed at the prompt, hit Ctrl+e (which jumps to the end of the line) followed by Ctrl+u (which deletes the text from the start of the line to the cursor).
See also https://unix.stackexchange.com/questions/195668/what-can-cause-an-item-to-be-deleted-from-my-bash-history/195726#195726 for a more detailed explanation of the technical background.
Simplest Way:
ctrl+r to search the command you want to delete/modify.
end to select the searched command to delete/modify- Delete or modify the selected command (don't press enter or ctrl + c)
up arrow(or ctrl+p) or down arrow(or ctrl+n) to select any other command.
ctrl+c That's it!
Note:
This changes only the current session commands. If we want to change older commands and save the changes we need to run following command before closing the terminal:
history -w
I'd like to add another method of modifying (or deleting) history entries, which I found rather accidentally when I was working with the bash:
To demonstrate this, start by executing the following three commands in bash:
$ echo 1
1
$ echo 2
2
$ echo 3
3
You can now select these commands again using the arrow keys or Ctrl+p and Ctrl+n.
Say you want to modify the first two commands. Move through history until echo 1
appears and change it to echo 1 - changed
, but DO NOT PRESS ENTER. If you now move further through your history, this line stays in its modified state and you can move away from and back to it. Now move to the line echo 2
and change it to echo 2 - changed
, again don't press enter. In order to save the changes to these lines, select any command in history except for these two, and hit Ctrl+c.
Of course, instead of modifying the history entry, you may also remove it which will result in an empty line at that entry. To delete the line currently displayed at the prompt, hit Ctrl+e (which jumps to the end of the line) followed by Ctrl+u (which deletes the text from the start of the line to the cursor).
See also https://unix.stackexchange.com/questions/195668/what-can-cause-an-item-to-be-deleted-from-my-bash-history/195726#195726 for a more detailed explanation of the technical background.
Simplest Way:
ctrl+r to search the command you want to delete/modify.
end to select the searched command to delete/modify- Delete or modify the selected command (don't press enter or ctrl + c)
up arrow(or ctrl+p) or down arrow(or ctrl+n) to select any other command.
ctrl+c That's it!
Note:
This changes only the current session commands. If we want to change older commands and save the changes we need to run following command before closing the terminal:
history -w
edited Feb 6 '18 at 19:02
Saurav Kumar
10.5k134665
10.5k134665
answered Jan 31 '18 at 16:15
Stefan HamckeStefan Hamcke
4851622
4851622
Many thanks Stefan! I must say that you brought an awesome things. Using this I found the most simplest way to modify/delete the history: 1.ctrl+r
to search the command you want to delete/modify. 2.end
to move the command and delete/modify the command. 3.ctrl+n
to go to next line and then 4.ctrl+c
– Saurav Kumar
Feb 1 '18 at 14:10
add a comment |
Many thanks Stefan! I must say that you brought an awesome things. Using this I found the most simplest way to modify/delete the history: 1.ctrl+r
to search the command you want to delete/modify. 2.end
to move the command and delete/modify the command. 3.ctrl+n
to go to next line and then 4.ctrl+c
– Saurav Kumar
Feb 1 '18 at 14:10
Many thanks Stefan! I must say that you brought an awesome things. Using this I found the most simplest way to modify/delete the history: 1.
ctrl+r
to search the command you want to delete/modify. 2. end
to move the command and delete/modify the command. 3. ctrl+n
to go to next line and then 4. ctrl+c
– Saurav Kumar
Feb 1 '18 at 14:10
Many thanks Stefan! I must say that you brought an awesome things. Using this I found the most simplest way to modify/delete the history: 1.
ctrl+r
to search the command you want to delete/modify. 2. end
to move the command and delete/modify the command. 3. ctrl+n
to go to next line and then 4. ctrl+c
– Saurav Kumar
Feb 1 '18 at 14:10
add a comment |
Use:
history -d OFFSET
to delete the history entry at offset OFFSET
even before it was added to your bash history file. To find out the right OFFSET
, you need only to run history
command. It's the number from from the start of the line which contain the history entry that you want to delete it.
And to save the modifications to the history use:
history -w
See more details in this guide.
not bad :) Good to get a new way..
– Saurav Kumar
Feb 27 '14 at 11:34
10
@SauravKumar Not bad?!? Probably is the best way...
– Radu Rădeanu
Mar 27 '14 at 17:04
5
READ FIRST: Just to be clear you must dohistory -w
afterwords to save the changes. Also OFFSET means which number thathistory
displays. If the line you are try to delete is 873 then usehistory -d 873
.
– Cammy_the_block
Aug 2 '14 at 16:07
2
@RaduRădeanu Usehistory -w
afterhistory -d
to save changes.
– Cammy_the_block
Aug 2 '14 at 16:09
20
This should be the correct answer.
– topher
Jun 3 '15 at 11:47
|
show 3 more comments
Use:
history -d OFFSET
to delete the history entry at offset OFFSET
even before it was added to your bash history file. To find out the right OFFSET
, you need only to run history
command. It's the number from from the start of the line which contain the history entry that you want to delete it.
And to save the modifications to the history use:
history -w
See more details in this guide.
not bad :) Good to get a new way..
– Saurav Kumar
Feb 27 '14 at 11:34
10
@SauravKumar Not bad?!? Probably is the best way...
– Radu Rădeanu
Mar 27 '14 at 17:04
5
READ FIRST: Just to be clear you must dohistory -w
afterwords to save the changes. Also OFFSET means which number thathistory
displays. If the line you are try to delete is 873 then usehistory -d 873
.
– Cammy_the_block
Aug 2 '14 at 16:07
2
@RaduRădeanu Usehistory -w
afterhistory -d
to save changes.
– Cammy_the_block
Aug 2 '14 at 16:09
20
This should be the correct answer.
– topher
Jun 3 '15 at 11:47
|
show 3 more comments
Use:
history -d OFFSET
to delete the history entry at offset OFFSET
even before it was added to your bash history file. To find out the right OFFSET
, you need only to run history
command. It's the number from from the start of the line which contain the history entry that you want to delete it.
And to save the modifications to the history use:
history -w
See more details in this guide.
Use:
history -d OFFSET
to delete the history entry at offset OFFSET
even before it was added to your bash history file. To find out the right OFFSET
, you need only to run history
command. It's the number from from the start of the line which contain the history entry that you want to delete it.
And to save the modifications to the history use:
history -w
See more details in this guide.
edited Aug 27 '14 at 7:54
PhoneixS
398616
398616
answered Feb 27 '14 at 10:14
user299481user299481
1,461262
1,461262
not bad :) Good to get a new way..
– Saurav Kumar
Feb 27 '14 at 11:34
10
@SauravKumar Not bad?!? Probably is the best way...
– Radu Rădeanu
Mar 27 '14 at 17:04
5
READ FIRST: Just to be clear you must dohistory -w
afterwords to save the changes. Also OFFSET means which number thathistory
displays. If the line you are try to delete is 873 then usehistory -d 873
.
– Cammy_the_block
Aug 2 '14 at 16:07
2
@RaduRădeanu Usehistory -w
afterhistory -d
to save changes.
– Cammy_the_block
Aug 2 '14 at 16:09
20
This should be the correct answer.
– topher
Jun 3 '15 at 11:47
|
show 3 more comments
not bad :) Good to get a new way..
– Saurav Kumar
Feb 27 '14 at 11:34
10
@SauravKumar Not bad?!? Probably is the best way...
– Radu Rădeanu
Mar 27 '14 at 17:04
5
READ FIRST: Just to be clear you must dohistory -w
afterwords to save the changes. Also OFFSET means which number thathistory
displays. If the line you are try to delete is 873 then usehistory -d 873
.
– Cammy_the_block
Aug 2 '14 at 16:07
2
@RaduRădeanu Usehistory -w
afterhistory -d
to save changes.
– Cammy_the_block
Aug 2 '14 at 16:09
20
This should be the correct answer.
– topher
Jun 3 '15 at 11:47
not bad :) Good to get a new way..
– Saurav Kumar
Feb 27 '14 at 11:34
not bad :) Good to get a new way..
– Saurav Kumar
Feb 27 '14 at 11:34
10
10
@SauravKumar Not bad?!? Probably is the best way...
– Radu Rădeanu
Mar 27 '14 at 17:04
@SauravKumar Not bad?!? Probably is the best way...
– Radu Rădeanu
Mar 27 '14 at 17:04
5
5
READ FIRST: Just to be clear you must do
history -w
afterwords to save the changes. Also OFFSET means which number that history
displays. If the line you are try to delete is 873 then use history -d 873
.– Cammy_the_block
Aug 2 '14 at 16:07
READ FIRST: Just to be clear you must do
history -w
afterwords to save the changes. Also OFFSET means which number that history
displays. If the line you are try to delete is 873 then use history -d 873
.– Cammy_the_block
Aug 2 '14 at 16:07
2
2
@RaduRădeanu Use
history -w
after history -d
to save changes.– Cammy_the_block
Aug 2 '14 at 16:09
@RaduRădeanu Use
history -w
after history -d
to save changes.– Cammy_the_block
Aug 2 '14 at 16:09
20
20
This should be the correct answer.
– topher
Jun 3 '15 at 11:47
This should be the correct answer.
– topher
Jun 3 '15 at 11:47
|
show 3 more comments
Edit the file ~/.bash_history
and delete the once with typos
For example, insert this command:
gedit ~/.bash_history
Edit something you like and after than save file and restart terminal.
The root command is:
sudo -i
inser your password
gedit ~/.bash_history
if you want to delete all history -c
should do the trick
SYNTAX
history
history [n]
history -c
history -d offset
history [-anrw] [filename]
history -ps arg
KEY
-c Clear the history list. This may be combined with
the other options to replace the history list completely.
-d offset
Delete the history entry at position offset.
offset should be specified as it appears when the history is displayed.
-a Append the new history lines (history lines entered since
the beginning of the current Bash session) to the history file.
-n Append the history lines not already read from the history
file
to the current history list. These are lines appended to the
history file since the beginning of the current Bash session.
-r Read the current history file and append its contents to the
history list.
-w Write out the current history to the history file.
-p Perform history substitution on the args and display the
result
on the standard output, without storing the results in the history list.
-s The args are added to the end of the history list as a single
entry.
source:
- history Man Page | Bash | SS64.com
Thanks it is helpful! Do you know how to delete the entry at the time when entered from command line? Or is there any command to delete the entry without opening the.bash_history
?
– Saurav Kumar
Sep 12 '13 at 9:39
1
@bladed19899history -c
doesn't work When I close terminal and open it again histories are not deleted. -1 your answer
– αғsнιη
Jun 14 '14 at 20:56
1
@KasiyA,-c Clear the history list. This may be combined with the other options to replace the history list completely.
source
– blade19899
Jun 16 '14 at 8:44
2
@KasiyA Usehistory -w
afterhistory -c
to write the changes.
– Cammy_the_block
Aug 2 '14 at 16:10
add a comment |
Edit the file ~/.bash_history
and delete the once with typos
For example, insert this command:
gedit ~/.bash_history
Edit something you like and after than save file and restart terminal.
The root command is:
sudo -i
inser your password
gedit ~/.bash_history
if you want to delete all history -c
should do the trick
SYNTAX
history
history [n]
history -c
history -d offset
history [-anrw] [filename]
history -ps arg
KEY
-c Clear the history list. This may be combined with
the other options to replace the history list completely.
-d offset
Delete the history entry at position offset.
offset should be specified as it appears when the history is displayed.
-a Append the new history lines (history lines entered since
the beginning of the current Bash session) to the history file.
-n Append the history lines not already read from the history
file
to the current history list. These are lines appended to the
history file since the beginning of the current Bash session.
-r Read the current history file and append its contents to the
history list.
-w Write out the current history to the history file.
-p Perform history substitution on the args and display the
result
on the standard output, without storing the results in the history list.
-s The args are added to the end of the history list as a single
entry.
source:
- history Man Page | Bash | SS64.com
Thanks it is helpful! Do you know how to delete the entry at the time when entered from command line? Or is there any command to delete the entry without opening the.bash_history
?
– Saurav Kumar
Sep 12 '13 at 9:39
1
@bladed19899history -c
doesn't work When I close terminal and open it again histories are not deleted. -1 your answer
– αғsнιη
Jun 14 '14 at 20:56
1
@KasiyA,-c Clear the history list. This may be combined with the other options to replace the history list completely.
source
– blade19899
Jun 16 '14 at 8:44
2
@KasiyA Usehistory -w
afterhistory -c
to write the changes.
– Cammy_the_block
Aug 2 '14 at 16:10
add a comment |
Edit the file ~/.bash_history
and delete the once with typos
For example, insert this command:
gedit ~/.bash_history
Edit something you like and after than save file and restart terminal.
The root command is:
sudo -i
inser your password
gedit ~/.bash_history
if you want to delete all history -c
should do the trick
SYNTAX
history
history [n]
history -c
history -d offset
history [-anrw] [filename]
history -ps arg
KEY
-c Clear the history list. This may be combined with
the other options to replace the history list completely.
-d offset
Delete the history entry at position offset.
offset should be specified as it appears when the history is displayed.
-a Append the new history lines (history lines entered since
the beginning of the current Bash session) to the history file.
-n Append the history lines not already read from the history
file
to the current history list. These are lines appended to the
history file since the beginning of the current Bash session.
-r Read the current history file and append its contents to the
history list.
-w Write out the current history to the history file.
-p Perform history substitution on the args and display the
result
on the standard output, without storing the results in the history list.
-s The args are added to the end of the history list as a single
entry.
source:
- history Man Page | Bash | SS64.com
Edit the file ~/.bash_history
and delete the once with typos
For example, insert this command:
gedit ~/.bash_history
Edit something you like and after than save file and restart terminal.
The root command is:
sudo -i
inser your password
gedit ~/.bash_history
if you want to delete all history -c
should do the trick
SYNTAX
history
history [n]
history -c
history -d offset
history [-anrw] [filename]
history -ps arg
KEY
-c Clear the history list. This may be combined with
the other options to replace the history list completely.
-d offset
Delete the history entry at position offset.
offset should be specified as it appears when the history is displayed.
-a Append the new history lines (history lines entered since
the beginning of the current Bash session) to the history file.
-n Append the history lines not already read from the history
file
to the current history list. These are lines appended to the
history file since the beginning of the current Bash session.
-r Read the current history file and append its contents to the
history list.
-w Write out the current history to the history file.
-p Perform history substitution on the args and display the
result
on the standard output, without storing the results in the history list.
-s The args are added to the end of the history list as a single
entry.
source:
- history Man Page | Bash | SS64.com
edited Mar 15 '17 at 12:40
Xan
1035
1035
answered Sep 12 '13 at 9:32
blade19899blade19899
17.6k18100161
17.6k18100161
Thanks it is helpful! Do you know how to delete the entry at the time when entered from command line? Or is there any command to delete the entry without opening the.bash_history
?
– Saurav Kumar
Sep 12 '13 at 9:39
1
@bladed19899history -c
doesn't work When I close terminal and open it again histories are not deleted. -1 your answer
– αғsнιη
Jun 14 '14 at 20:56
1
@KasiyA,-c Clear the history list. This may be combined with the other options to replace the history list completely.
source
– blade19899
Jun 16 '14 at 8:44
2
@KasiyA Usehistory -w
afterhistory -c
to write the changes.
– Cammy_the_block
Aug 2 '14 at 16:10
add a comment |
Thanks it is helpful! Do you know how to delete the entry at the time when entered from command line? Or is there any command to delete the entry without opening the.bash_history
?
– Saurav Kumar
Sep 12 '13 at 9:39
1
@bladed19899history -c
doesn't work When I close terminal and open it again histories are not deleted. -1 your answer
– αғsнιη
Jun 14 '14 at 20:56
1
@KasiyA,-c Clear the history list. This may be combined with the other options to replace the history list completely.
source
– blade19899
Jun 16 '14 at 8:44
2
@KasiyA Usehistory -w
afterhistory -c
to write the changes.
– Cammy_the_block
Aug 2 '14 at 16:10
Thanks it is helpful! Do you know how to delete the entry at the time when entered from command line? Or is there any command to delete the entry without opening the
.bash_history
?– Saurav Kumar
Sep 12 '13 at 9:39
Thanks it is helpful! Do you know how to delete the entry at the time when entered from command line? Or is there any command to delete the entry without opening the
.bash_history
?– Saurav Kumar
Sep 12 '13 at 9:39
1
1
@bladed19899
history -c
doesn't work When I close terminal and open it again histories are not deleted. -1 your answer– αғsнιη
Jun 14 '14 at 20:56
@bladed19899
history -c
doesn't work When I close terminal and open it again histories are not deleted. -1 your answer– αғsнιη
Jun 14 '14 at 20:56
1
1
@KasiyA,
-c Clear the history list. This may be combined with the other options to replace the history list completely.
source– blade19899
Jun 16 '14 at 8:44
@KasiyA,
-c Clear the history list. This may be combined with the other options to replace the history list completely.
source– blade19899
Jun 16 '14 at 8:44
2
2
@KasiyA Use
history -w
after history -c
to write the changes.– Cammy_the_block
Aug 2 '14 at 16:10
@KasiyA Use
history -w
after history -c
to write the changes.– Cammy_the_block
Aug 2 '14 at 16:10
add a comment |
If you want to immediately delete it form the same terminal first you have to add the following to your ~/.bashrc file.
PROMPT_COMMAND='history -a'
and restart your terminal.
You can add it anywhere in .bashrc file .I have added as below along with other history related stuff.
Usually during a bash session the executed commands are not written into .bash_history until the session is terminated hence PROMPT_COMMAND='history -a'
enters the command then and there into .bash_history.
Now whenever you make mistake or error in a command and want to delete it then and there just execute the following
sed -i '$d' ~/.bash_history
and tada it would be deleted.
To make it simpler you can alias it to something more simpler and use it such as
alias rh ='sed -i '''$d''' ~/.bash_history'
So executing rh
will remove the last executed command from history.
The above is temporary aliasing which only lasts for a session.To make it permanent or persistent add
alias rh = 'sed -i '''$d''' ~/.bash_history'
to .bashrc
NOTE
There should not be any space on both sides of =
If You Dont Want to Alias then You could also do the following
Make a commad name rh
and place it in /bin
directory:
Open a file say
rh
and paste following code, save and close:
sed -i '$d' ~/.bash_history
Make
rh
executable and place it in/bin
directory:
chmod +x rh
sudo cp rh /binNow use
rh
command to delete recent command from history.
Where to addPROMPT_COMMAND='history -a'
in.bashrc
file? And what exactly it will do? I triedsed -i '$d' ~/.bash_history
it's working without editing.bashrc
!! But alias thing is not working.. I will accept your answer if you just elaborate my question and make alias working.. :)
– Saurav Kumar
Sep 12 '13 at 15:15
@SauravKumar have edited the answer. Had missed the single and double quotes in aliasing command.. My bad.. :P
– Stormvirux
Sep 12 '13 at 16:29
Believe me or not.. alias thing is still not working.. It executes without any error but doesn't delete the entry from.bash_history
file.. :P any way.. Not a problem.. I made my own command and placed it in/bin
directory. Since because of your command:sed -i "$d" ~/.bash_history
it is working fine. I accept your answer.. :)
– Saurav Kumar
Sep 12 '13 at 16:48
If you don't mind, I would like to edit your answer so that it would be helpful to others..
– Saurav Kumar
Sep 12 '13 at 16:51
Actually I edited it. You've to approve it..
– Saurav Kumar
Sep 12 '13 at 17:27
|
show 2 more comments
If you want to immediately delete it form the same terminal first you have to add the following to your ~/.bashrc file.
PROMPT_COMMAND='history -a'
and restart your terminal.
You can add it anywhere in .bashrc file .I have added as below along with other history related stuff.
Usually during a bash session the executed commands are not written into .bash_history until the session is terminated hence PROMPT_COMMAND='history -a'
enters the command then and there into .bash_history.
Now whenever you make mistake or error in a command and want to delete it then and there just execute the following
sed -i '$d' ~/.bash_history
and tada it would be deleted.
To make it simpler you can alias it to something more simpler and use it such as
alias rh ='sed -i '''$d''' ~/.bash_history'
So executing rh
will remove the last executed command from history.
The above is temporary aliasing which only lasts for a session.To make it permanent or persistent add
alias rh = 'sed -i '''$d''' ~/.bash_history'
to .bashrc
NOTE
There should not be any space on both sides of =
If You Dont Want to Alias then You could also do the following
Make a commad name rh
and place it in /bin
directory:
Open a file say
rh
and paste following code, save and close:
sed -i '$d' ~/.bash_history
Make
rh
executable and place it in/bin
directory:
chmod +x rh
sudo cp rh /binNow use
rh
command to delete recent command from history.
Where to addPROMPT_COMMAND='history -a'
in.bashrc
file? And what exactly it will do? I triedsed -i '$d' ~/.bash_history
it's working without editing.bashrc
!! But alias thing is not working.. I will accept your answer if you just elaborate my question and make alias working.. :)
– Saurav Kumar
Sep 12 '13 at 15:15
@SauravKumar have edited the answer. Had missed the single and double quotes in aliasing command.. My bad.. :P
– Stormvirux
Sep 12 '13 at 16:29
Believe me or not.. alias thing is still not working.. It executes without any error but doesn't delete the entry from.bash_history
file.. :P any way.. Not a problem.. I made my own command and placed it in/bin
directory. Since because of your command:sed -i "$d" ~/.bash_history
it is working fine. I accept your answer.. :)
– Saurav Kumar
Sep 12 '13 at 16:48
If you don't mind, I would like to edit your answer so that it would be helpful to others..
– Saurav Kumar
Sep 12 '13 at 16:51
Actually I edited it. You've to approve it..
– Saurav Kumar
Sep 12 '13 at 17:27
|
show 2 more comments
If you want to immediately delete it form the same terminal first you have to add the following to your ~/.bashrc file.
PROMPT_COMMAND='history -a'
and restart your terminal.
You can add it anywhere in .bashrc file .I have added as below along with other history related stuff.
Usually during a bash session the executed commands are not written into .bash_history until the session is terminated hence PROMPT_COMMAND='history -a'
enters the command then and there into .bash_history.
Now whenever you make mistake or error in a command and want to delete it then and there just execute the following
sed -i '$d' ~/.bash_history
and tada it would be deleted.
To make it simpler you can alias it to something more simpler and use it such as
alias rh ='sed -i '''$d''' ~/.bash_history'
So executing rh
will remove the last executed command from history.
The above is temporary aliasing which only lasts for a session.To make it permanent or persistent add
alias rh = 'sed -i '''$d''' ~/.bash_history'
to .bashrc
NOTE
There should not be any space on both sides of =
If You Dont Want to Alias then You could also do the following
Make a commad name rh
and place it in /bin
directory:
Open a file say
rh
and paste following code, save and close:
sed -i '$d' ~/.bash_history
Make
rh
executable and place it in/bin
directory:
chmod +x rh
sudo cp rh /binNow use
rh
command to delete recent command from history.
If you want to immediately delete it form the same terminal first you have to add the following to your ~/.bashrc file.
PROMPT_COMMAND='history -a'
and restart your terminal.
You can add it anywhere in .bashrc file .I have added as below along with other history related stuff.
Usually during a bash session the executed commands are not written into .bash_history until the session is terminated hence PROMPT_COMMAND='history -a'
enters the command then and there into .bash_history.
Now whenever you make mistake or error in a command and want to delete it then and there just execute the following
sed -i '$d' ~/.bash_history
and tada it would be deleted.
To make it simpler you can alias it to something more simpler and use it such as
alias rh ='sed -i '''$d''' ~/.bash_history'
So executing rh
will remove the last executed command from history.
The above is temporary aliasing which only lasts for a session.To make it permanent or persistent add
alias rh = 'sed -i '''$d''' ~/.bash_history'
to .bashrc
NOTE
There should not be any space on both sides of =
If You Dont Want to Alias then You could also do the following
Make a commad name rh
and place it in /bin
directory:
Open a file say
rh
and paste following code, save and close:
sed -i '$d' ~/.bash_history
Make
rh
executable and place it in/bin
directory:
chmod +x rh
sudo cp rh /binNow use
rh
command to delete recent command from history.
edited Feb 3 '16 at 16:51
answered Sep 12 '13 at 10:54
StormviruxStormvirux
3,8161831
3,8161831
Where to addPROMPT_COMMAND='history -a'
in.bashrc
file? And what exactly it will do? I triedsed -i '$d' ~/.bash_history
it's working without editing.bashrc
!! But alias thing is not working.. I will accept your answer if you just elaborate my question and make alias working.. :)
– Saurav Kumar
Sep 12 '13 at 15:15
@SauravKumar have edited the answer. Had missed the single and double quotes in aliasing command.. My bad.. :P
– Stormvirux
Sep 12 '13 at 16:29
Believe me or not.. alias thing is still not working.. It executes without any error but doesn't delete the entry from.bash_history
file.. :P any way.. Not a problem.. I made my own command and placed it in/bin
directory. Since because of your command:sed -i "$d" ~/.bash_history
it is working fine. I accept your answer.. :)
– Saurav Kumar
Sep 12 '13 at 16:48
If you don't mind, I would like to edit your answer so that it would be helpful to others..
– Saurav Kumar
Sep 12 '13 at 16:51
Actually I edited it. You've to approve it..
– Saurav Kumar
Sep 12 '13 at 17:27
|
show 2 more comments
Where to addPROMPT_COMMAND='history -a'
in.bashrc
file? And what exactly it will do? I triedsed -i '$d' ~/.bash_history
it's working without editing.bashrc
!! But alias thing is not working.. I will accept your answer if you just elaborate my question and make alias working.. :)
– Saurav Kumar
Sep 12 '13 at 15:15
@SauravKumar have edited the answer. Had missed the single and double quotes in aliasing command.. My bad.. :P
– Stormvirux
Sep 12 '13 at 16:29
Believe me or not.. alias thing is still not working.. It executes without any error but doesn't delete the entry from.bash_history
file.. :P any way.. Not a problem.. I made my own command and placed it in/bin
directory. Since because of your command:sed -i "$d" ~/.bash_history
it is working fine. I accept your answer.. :)
– Saurav Kumar
Sep 12 '13 at 16:48
If you don't mind, I would like to edit your answer so that it would be helpful to others..
– Saurav Kumar
Sep 12 '13 at 16:51
Actually I edited it. You've to approve it..
– Saurav Kumar
Sep 12 '13 at 17:27
Where to add
PROMPT_COMMAND='history -a'
in .bashrc
file? And what exactly it will do? I tried sed -i '$d' ~/.bash_history
it's working without editing .bashrc
!! But alias thing is not working.. I will accept your answer if you just elaborate my question and make alias working.. :)– Saurav Kumar
Sep 12 '13 at 15:15
Where to add
PROMPT_COMMAND='history -a'
in .bashrc
file? And what exactly it will do? I tried sed -i '$d' ~/.bash_history
it's working without editing .bashrc
!! But alias thing is not working.. I will accept your answer if you just elaborate my question and make alias working.. :)– Saurav Kumar
Sep 12 '13 at 15:15
@SauravKumar have edited the answer. Had missed the single and double quotes in aliasing command.. My bad.. :P
– Stormvirux
Sep 12 '13 at 16:29
@SauravKumar have edited the answer. Had missed the single and double quotes in aliasing command.. My bad.. :P
– Stormvirux
Sep 12 '13 at 16:29
Believe me or not.. alias thing is still not working.. It executes without any error but doesn't delete the entry from
.bash_history
file.. :P any way.. Not a problem.. I made my own command and placed it in /bin
directory. Since because of your command: sed -i "$d" ~/.bash_history
it is working fine. I accept your answer.. :)– Saurav Kumar
Sep 12 '13 at 16:48
Believe me or not.. alias thing is still not working.. It executes without any error but doesn't delete the entry from
.bash_history
file.. :P any way.. Not a problem.. I made my own command and placed it in /bin
directory. Since because of your command: sed -i "$d" ~/.bash_history
it is working fine. I accept your answer.. :)– Saurav Kumar
Sep 12 '13 at 16:48
If you don't mind, I would like to edit your answer so that it would be helpful to others..
– Saurav Kumar
Sep 12 '13 at 16:51
If you don't mind, I would like to edit your answer so that it would be helpful to others..
– Saurav Kumar
Sep 12 '13 at 16:51
Actually I edited it. You've to approve it..
– Saurav Kumar
Sep 12 '13 at 17:27
Actually I edited it. You've to approve it..
– Saurav Kumar
Sep 12 '13 at 17:27
|
show 2 more comments
If you are using "set -o vi" option in bash (very useful to search back with Escape key), then you can search for the line and delete the line with "dd" in the same way you do in "vi".
I find that I have to typej
ork
afterdd
to make it actually clear the command from history. If I type another command, or just pressEnter
, bash seems to assume it's just a new command and that it should retain the old command in history. It's also interesting to note that when it's done right, it clears the command, but doesn't delete it—the result is blank history entries. But this is good enough for removing passwords that I was forced to type at the command line, and much easier than other answers, so thanks very much for posting this!
– Michael Scheper
Jan 12 '18 at 0:30
add a comment |
If you are using "set -o vi" option in bash (very useful to search back with Escape key), then you can search for the line and delete the line with "dd" in the same way you do in "vi".
I find that I have to typej
ork
afterdd
to make it actually clear the command from history. If I type another command, or just pressEnter
, bash seems to assume it's just a new command and that it should retain the old command in history. It's also interesting to note that when it's done right, it clears the command, but doesn't delete it—the result is blank history entries. But this is good enough for removing passwords that I was forced to type at the command line, and much easier than other answers, so thanks very much for posting this!
– Michael Scheper
Jan 12 '18 at 0:30
add a comment |
If you are using "set -o vi" option in bash (very useful to search back with Escape key), then you can search for the line and delete the line with "dd" in the same way you do in "vi".
If you are using "set -o vi" option in bash (very useful to search back with Escape key), then you can search for the line and delete the line with "dd" in the same way you do in "vi".
answered Oct 28 '17 at 22:05
The IT GuyThe IT Guy
112
112
I find that I have to typej
ork
afterdd
to make it actually clear the command from history. If I type another command, or just pressEnter
, bash seems to assume it's just a new command and that it should retain the old command in history. It's also interesting to note that when it's done right, it clears the command, but doesn't delete it—the result is blank history entries. But this is good enough for removing passwords that I was forced to type at the command line, and much easier than other answers, so thanks very much for posting this!
– Michael Scheper
Jan 12 '18 at 0:30
add a comment |
I find that I have to typej
ork
afterdd
to make it actually clear the command from history. If I type another command, or just pressEnter
, bash seems to assume it's just a new command and that it should retain the old command in history. It's also interesting to note that when it's done right, it clears the command, but doesn't delete it—the result is blank history entries. But this is good enough for removing passwords that I was forced to type at the command line, and much easier than other answers, so thanks very much for posting this!
– Michael Scheper
Jan 12 '18 at 0:30
I find that I have to type
j
or k
after dd
to make it actually clear the command from history. If I type another command, or just press Enter
, bash seems to assume it's just a new command and that it should retain the old command in history. It's also interesting to note that when it's done right, it clears the command, but doesn't delete it—the result is blank history entries. But this is good enough for removing passwords that I was forced to type at the command line, and much easier than other answers, so thanks very much for posting this!– Michael Scheper
Jan 12 '18 at 0:30
I find that I have to type
j
or k
after dd
to make it actually clear the command from history. If I type another command, or just press Enter
, bash seems to assume it's just a new command and that it should retain the old command in history. It's also interesting to note that when it's done right, it clears the command, but doesn't delete it—the result is blank history entries. But this is good enough for removing passwords that I was forced to type at the command line, and much easier than other answers, so thanks very much for posting this!– Michael Scheper
Jan 12 '18 at 0:30
add a comment |
to remove multiple lines (e.g. from 1974 to 1990, check with history
command):
for i in `seq 1974 1990` ; do history -d 1974 ; done
note that the line number to remove is always the same, as you are removing that one constantly and go to the next.
The note is very important.
– Weijun Zhou
Nov 24 '18 at 14:30
add a comment |
to remove multiple lines (e.g. from 1974 to 1990, check with history
command):
for i in `seq 1974 1990` ; do history -d 1974 ; done
note that the line number to remove is always the same, as you are removing that one constantly and go to the next.
The note is very important.
– Weijun Zhou
Nov 24 '18 at 14:30
add a comment |
to remove multiple lines (e.g. from 1974 to 1990, check with history
command):
for i in `seq 1974 1990` ; do history -d 1974 ; done
note that the line number to remove is always the same, as you are removing that one constantly and go to the next.
to remove multiple lines (e.g. from 1974 to 1990, check with history
command):
for i in `seq 1974 1990` ; do history -d 1974 ; done
note that the line number to remove is always the same, as you are removing that one constantly and go to the next.
answered Sep 27 '18 at 9:16
törzsmókustörzsmókus
317212
317212
The note is very important.
– Weijun Zhou
Nov 24 '18 at 14:30
add a comment |
The note is very important.
– Weijun Zhou
Nov 24 '18 at 14:30
The note is very important.
– Weijun Zhou
Nov 24 '18 at 14:30
The note is very important.
– Weijun Zhou
Nov 24 '18 at 14:30
add a comment |
I had a situation where I had superfluous entries in my bash history from a Yubikey- maybe 50 or so, matching 'ccccc.....'. Ideally, I wanted a way to delete entries matching a pattern, which I suppose you could do with sed or something, assuming your history ignores blanks.
Anyway, I got lazy and ended up using vim, searching for 'cccc' and using 'dd' while cycling through every match. Didn't take more than a minute.
1
If you are doing this in vim then you could also do :g/cccc/d or :g/^cccc/d: or use a macro qqnddq then @@ (assumes your last search was for ccccc).
– htaccess
Jan 12 at 3:19
@htaccess That would certainly have been easier, but I kind of wanted to visually inspect the rest of the file at the same time.
– Dylan_Larkin
Jan 24 at 4:54
add a comment |
I had a situation where I had superfluous entries in my bash history from a Yubikey- maybe 50 or so, matching 'ccccc.....'. Ideally, I wanted a way to delete entries matching a pattern, which I suppose you could do with sed or something, assuming your history ignores blanks.
Anyway, I got lazy and ended up using vim, searching for 'cccc' and using 'dd' while cycling through every match. Didn't take more than a minute.
1
If you are doing this in vim then you could also do :g/cccc/d or :g/^cccc/d: or use a macro qqnddq then @@ (assumes your last search was for ccccc).
– htaccess
Jan 12 at 3:19
@htaccess That would certainly have been easier, but I kind of wanted to visually inspect the rest of the file at the same time.
– Dylan_Larkin
Jan 24 at 4:54
add a comment |
I had a situation where I had superfluous entries in my bash history from a Yubikey- maybe 50 or so, matching 'ccccc.....'. Ideally, I wanted a way to delete entries matching a pattern, which I suppose you could do with sed or something, assuming your history ignores blanks.
Anyway, I got lazy and ended up using vim, searching for 'cccc' and using 'dd' while cycling through every match. Didn't take more than a minute.
I had a situation where I had superfluous entries in my bash history from a Yubikey- maybe 50 or so, matching 'ccccc.....'. Ideally, I wanted a way to delete entries matching a pattern, which I suppose you could do with sed or something, assuming your history ignores blanks.
Anyway, I got lazy and ended up using vim, searching for 'cccc' and using 'dd' while cycling through every match. Didn't take more than a minute.
answered Jan 11 at 20:39
Dylan_LarkinDylan_Larkin
101
101
1
If you are doing this in vim then you could also do :g/cccc/d or :g/^cccc/d: or use a macro qqnddq then @@ (assumes your last search was for ccccc).
– htaccess
Jan 12 at 3:19
@htaccess That would certainly have been easier, but I kind of wanted to visually inspect the rest of the file at the same time.
– Dylan_Larkin
Jan 24 at 4:54
add a comment |
1
If you are doing this in vim then you could also do :g/cccc/d or :g/^cccc/d: or use a macro qqnddq then @@ (assumes your last search was for ccccc).
– htaccess
Jan 12 at 3:19
@htaccess That would certainly have been easier, but I kind of wanted to visually inspect the rest of the file at the same time.
– Dylan_Larkin
Jan 24 at 4:54
1
1
If you are doing this in vim then you could also do :g/cccc/d or :g/^cccc/d: or use a macro qqnddq then @@ (assumes your last search was for ccccc).
– htaccess
Jan 12 at 3:19
If you are doing this in vim then you could also do :g/cccc/d or :g/^cccc/d: or use a macro qqnddq then @@ (assumes your last search was for ccccc).
– htaccess
Jan 12 at 3:19
@htaccess That would certainly have been easier, but I kind of wanted to visually inspect the rest of the file at the same time.
– Dylan_Larkin
Jan 24 at 4:54
@htaccess That would certainly have been easier, but I kind of wanted to visually inspect the rest of the file at the same time.
– Dylan_Larkin
Jan 24 at 4:54
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%2f344593%2fhow-to-delete-selected-results-from-bash-history%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
5
Please, change the accepted answer, there are other with more that 100 up votes.
– greuze
Sep 27 '17 at 14:20
1
@greuze: Changed to the best answer. Count of votes doesn't mean that it's the best!
– Saurav Kumar
Apr 20 '18 at 13:09