Based on the answer to the comment up above, it appears your are overriding TERM in one of your startup scripts. While inside screen, your TERM should be set to 'screen', not 'xterm-256color'.
I would look through your shell startup scripts. ~/.bashrc, /etc/bash/bashrc, and possibly others like ~/.bash_profile and /etc/profile depending on how you have everything set up. If you see any TERM="..." settings, you need to remove those.
You can use HISTIGNORE
environment variable.
A colon-separated list of patterns used to decide which command lines should be saved on the history list. For example:
export HISTIGNORE="cd*:ls*"
this will ignore all cd and ls commands from history.
EDIT:
sorry, In my first reading I didn't take sufficent care to your question. Btw, you are right: HISTIGNORE
is a very hard setting, and bash_history will simply ignore each command that is listed in this variable (it will ignore it at the moment you execute it, if there are already entries with these command into your HISTFILE
they will be found by history reverse search.
To first answer to your last question, live and written history may vary a lot if you use different terminals simultaneously. You could try a solution as described here:
Preserve bash history in multiple terminal windows
What you could imagine is a solution in which you use a function in your ~/.bash_logout
file, which will erase the history entries that you do not want.
something like this should do what you want:
function clear_history(){
# hist_ignore regex, this may be done in a more fancy way,
# such as using an env variable, but anyway
MYHISTIGNORE='^cd:^view:^cat'
# write down history to file
history -w
# create a new tmp file for history
tmpFile=$(mktemp)
cp ${HISTFILE} ${tmpFile}
# use it to filter history
for myRegex in $(echo $MYHISTIGNORE | awk 'BEGIN{FS=":"}{for (i=1;i<=NF;i++){print $i}}'); do
sed -i "/${myRegex}/d" ${tmpFile}
done
# and copy it back to history file
mv ${tmpFile} ${HISTFILE}
}
Best Answer
you need to take a look at the bash
fc
command.If you want to edit before rexecuting a history line just do like this
where
123
is the history line number you see typing the commandhistory
.It will open your favorite editor and allow you to modifiy the line then quit and save and it will run.
You can also do it a range of command like this:
To work on command history from 123 to 135.
Edit 1:
if you need to run without edit consider watch the post Re-execute fc command from history