how to edit history to remove few commands executed
Hi
suppose when I issue history command it is showing 100 entries with number attached to each command executed. please tell me how to edit the history to remove few commands executed by me so as to protect the system from other users. |
That's a pretty odd request, and only really goes to highlight someone trying to hide the fact that they have done stuff they don't want anyone else finding out about... Other users should be other user accounts, so as long as they don't have root access, they can't see your bash history file. you can just mess with the ~/.bash_history file if you really have to, but note that it's not written to until you log out, so recently run commands will not be in there yet.
|
Quote:
my intention is not that. I only want to save the system from users who are enthusiastic but not knowing what they are doing? |
Quote:
Quote:
Quote:
Quote:
Quote:
|
Code:
I only want to save the system from users who are enthusiastic but not knowing what they are doing? |
so no one else has accidentalyy typed there password in the wrong window or box, only to have it show in history. And would not like to delete all history, or change favorite password?
hmmmm. |
Quote:
|
Quote:
|
Quote:
|
Not the right answer... Need information, not acid.
Quote:
The most important reason for deleting a command is that it might have been a typo, or even a wrong operation or a destructive operation (like a bad rm), and to recall such over and over again is one of the most infuriating things in the Linux/Unix command line history. I have sessions with several shells sharing the history and to find some odd ancient command popping up after every logout and a login is to put it simply, a waste of time. I have also repeatedly been looking for a tool allowing me to selectively remove some commands from my history. On Windows we have this great developer shell "take command" (former 4nt) by JP Soft. There I can flexibly adjust the way how history works (append or merge a command, reorder to be last etc, etc) and I can selectively remove some commands by selecting them and pressing "del". I do such command cleanup on a regular base, foremost when a phase of a project is over. Lack of it is a titanic inconvenience with 'fc' on Unix. On several occasions I used strings on .sh_history and recreated this file by executing commands which matter because this recalling of what I thought should have been replaced by more recent commands many times over, but it was not. The problem is that when more than one shell shares the history file, I think that it will be overwritten by the last logout, and its history. But I am not sure, such erratic are the results. Logout last from the least used window, and all the recent stuff is lost. This happens to me over and over again. Totally inconvenient. So the question is: Do we have a tool of a kind, or any simple method to selectively delete some commands from the history? Offset like the -d option does not cut it. |
Quote:
|
This script displays bash history lines and asks for a list of line numbers for deletion. It then displays the edited history and asks for more line numbers. It exits this loop if nothing is entered.
The line numbers must be from the current display because when commands are deleted the commands after them move down to new line numbers. The lines are deleted in memory not from the history file. The current history in memory can be written to the history file with 'history -w' The script doesn't use any external commands, only bash. It has to be sourced into the terminal i.e. preceded by a dot and a space: . scriptname Code:
# This bash script must be used with 'source' or '.' |
ow to edit history to remove few commands executed
This has puzzled me for ages,I came across this solution today:
on the command line run: for i in {344..334}; do history -d $i; done Note the selections of lines are in reverse order. This is where I found it http://lists.gnu.org/archive/html/bu.../msg00056.html Hope this helps ! |
note that ~/.bash_history is just a text file. open it up and delete any entry you want.
|
Hello,
Yes DJ Shaji, I know this and have been editing ~/.bash_history with vim for years.This code I gave yesterday is far faster and more efficient, if for example you just want remove say more than a couple of entries; by the time you have opened vim or another text editor,deleted what you wanted to, done :wq in vim to close and write to disk, you could have run this code without opening any editor, job done! Q.E.D. |
All times are GMT -5. The time now is 07:07 AM. |