There are different ways to accomplish this task, but lets clarify something before going further.
There is a file named:
~/.bash_history
, which contains your older terminal sessions history, whenever you close your terminal, your history will be saved there.
At the same time the history of your old sessions along with current session is temporary accessible by
history
commands until you close the terminal which then will be saved into ~/.bash_history
file.
So if you remove 5 lines at the end of
~/.bash_history
, then closing terminal will cause your current command to be accessible at next sessions.You can follow this step to delete the history
- Typing
history -d <line_number>
deletes a specified line from the history in memory. - Typing
history -w
writes the current in-memory history to the~/.bash_history
file.
- After we typing
history -w
the in memory history write to ~/.bash_history
history file ~/.bash_history before we typing
history -w
as shown bellow
After we typing
history -w
the in memory history write to ~/.bash_history
If you want to delete more than 1 line you can delete using vi by open the
~/.bash_history
. file
You need to log out and back in or run
history -a
so the current history is committed to disk.
Then just edit the file
~/.bash_history
.
You can read the option of history command as shown bellow, you can also can read manual of history command by typing man history
Source :
https://superuser.com/questions/384366/remove-a-certain-line-from-bash-history-file/384383#384383
Tidak ada komentar :
Posting Komentar