![]() ![]() Note: if your sensitive information pattern contains slash(es), bash_historyĪnd delete all lines containing the sensitive info. Then sed will use the text that you typed to search. Thus making it ineligible for inclusion in the history record. Without actually typing it into the command line, This is a trick to let you enter (part of) a command Just type the information that you want to delete from the file. It will appear that your terminal is hung (there won't be a prompt) This will run head -n1 with input from the terminal. So you could: sed -e "/$(head -n1)/d" -i. bash_historyīut, as you type this, you create another history line containing the search pattern (sensitive info) you are trying to delete. If you realize that sensitive information is already stored, and you want to delete it, but not your entire history:Ī simple sed command could do the job: sed -e '/SeNsItIvE InFo/d' -i. Type ↑ (up arrow) in the open bash session until the sensitive information is shown, then use line editing keystrokes like Ctrl+ W to delete the sensitive info, and then ↓ (down arrow) until a new empty line is prompted, before typing Enter.ĭelete sensitive information from the history file If you've entered some password on a command line, then realize that all commands are logged, you could either:įorce exit the current session without saving history: kill -9 $$ Several techniques: Prevent sensitive information from being stored in the history file Of course for history items already on disk, the alternative to editing the history with history -d commands then issuing history -w, is to edit the $HISTFILE with a text editor. To overwrite the $HISTFILE with the current session's view of the entire history, right now, issue: (bash)$ history -w Manipulating the history with the above commands will still only append the remaining new items to the $HISTFILE, on exit. If, however, the command(s) you wish to remove are from a previous session, they will have already been appended to the $HISTFILE on exit. The approach so far is to not even let sensitive history items be written to disk for extra security, because in theory data deleted from non-volatile media can still be recovered. If you don't want any history from your current session to hit the disk, exit using: (bash)$ kill -9 $$ (Without ignorespace, it would be 603.599.) ![]() ![]() ![]() Then issue: (bash)$ for i in do history -d $i done If you want to delete the last few commands, find the last and first history number: (bash)$ history 5 Note the leading space this command requires ignorespace, otherwise it'll just delete itself! To delete the previous command in history, issue: (bash)$ history -d $((HISTCMD-1)) If you accidentally put an unwanted command into history, providing that your bash session is still open, the command hasn't yet touched the disk. # One-off recursive remove mustn't be accidentally repeated! Then proceed any command you don't want in your history with a space: (bash)$ sensitive-cmd-with -password 82cf7dfe Make sure that $HISTCONTROL contains ignorespace: (bash)$ echo $HISTCONTROL First of all, if the command you're about to issue is sensitive, unsafe, or you just don't need it cluttering up your history, it is best/quickest to just prevent it from entering the history in the first place. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |