0

I am not really good with Linux but I got one premade server which has Linux on it to supervise.

The OS is CentOS 7. I noticed that the up arrow allows the search of past commands (not only for the current session but for all) but for specific reasons I want to remove that option. As far as I can find \etc\bashrc has no line with \e[A while in \etc\inputrc there was a line for history-search-backwards but for \e[5~. I commented that line but nothing changed. As for ~/.inputrc file it does not exist.

So how can I remove the up arrow search history function?

4
  • 1
    Do you want to remove just the ability to use the up arrow to search the history, or 1) any way to search the history from the shell or 2) the record of the commands you've run in the past, independent of whether you're using the shell or not? Jan 22 at 7:58
  • I want to remove just the ability to use the up arrow to search history. The only way I want history to be read is by typing in the adequate command
    – UrosT
    Jan 22 at 10:46
  • Do bind -p -- that will show the current bindings. You'll want to remove the ones for "previous-history" (and presumably "next-history" as well). Jan 22 at 17:30
  • @glennjackman This works but only for one session. When I open a new session the up arrow still works. Is there a way to remove the bind for all sessions?
    – UrosT
    Jan 27 at 11:24
1

To see what keys are bound to previous-history:

bind -q previous-history

You'll get something like

previous-history can be invoked via "\eOA", "\e[A".

Then, for each of those:

echo '"\eOA": ""' >> ~/.inputrc
echo '"\e[A": ""' >> ~/.inputrc

Start a new bash session, and that bind -q command will tell you

previous-history is not bound to any keys.

As a user inconvenienced by this restriction, I would do set -o vi and then use Esc and k/j to go up/down in history

2
  • Thanks this fixed it I think. For all but one account on the server. For that one account I get Permission denied even with sudo. Is there any workaround for this since I don't want to change privileges of that user?
    – UrosT
    Feb 3 at 6:55
  • Do you mean you get that error when you try to write to the file? Note that bash performs the redirection as you and runs the command with sudo. You'll need echo "..." | sudo tee -a file to elevate privs to write to a file. Feb 3 at 11:52
0

Depending on your needs you have the following solutions:

If you want to erase your history from time to time:

history -c

If you want to permanently disable bash history:

echo 'set +o history' >> ~/.bashrc

If you want to hide only some lines from your bash history:

Add to ~/.bashrc the following line:

export HISTCONTROL=ignorespace

Reload .bashrc

source ~/.bashrc

Then, when you don't want a command to be recorded you just have to start this command with an empty space

1
  • The option I am looking for is just to remove the option to bring up pass commands by using the up arrow. I still want the history to be there and to be readable by executing the needed command
    – UrosT
    Jan 22 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.