If no commands can be run using ↑ or ↓ that indicates that your history file is empty or you have no read-permissions. Check that.
Maybe you run the commands as another user. If so do:
su otheruser
history 10
and look at the output.
If you change $HISTFILESIZE
the changes will be overwritten, whenever you invoke an other shell. To prevent that you should change that variable in your .bashrc
. Also you should set the variable $HISTSIZE
to a larger value.
Generally usefull tips using histories:
Ctrl+R does a reverse search of your history for you. Alt+. pastes the last argument of the last command into your prompt at cursor position.
Also the bang (!
) operator will repeat commands for you in terminal (if it's just about saving you some typing. Example:
confus@confusion:~$ echo "bang + letters will repeat the last command starting with these letters."
bang + letters will repeat the last command starting with these letters.
confus@confusion:~$ clear
confus@confusion:~$ !ech
bang + letters will repeat the last command starting with these letters.
All those histroy related things are stored in the home directory of any user in a file called .bash_history
. You can look them up by using the history
-command. Her is a small tutorial on howto use history.
confus@confus:~$ history 4 #will print last 4 commands
1848 ls
1849 clear
1850 vi /home/confus/.local/share/applications/nautilus-home.desktop
1851 history 4
Another very usefull thing is to create a .inputrc
file in your home directory with the following content:
"\e\e[C": forward-word
"\e\e[D": backward-word
"\e[A": history-search-backward
"\e[B": history-search-forward
This way you can use the ↑ or ↓ to complete commands you started to type from history. E.g. when you type a rather lenghty command such as rsync -a -v --human-readable --prune-empty-dirs -e 'ssh -i .ssh/id_rsa' --include="*/" --exclude="snapshot_*" --exclude="restart.*" /scratch/ x@cluster1:/home/x/runs/
and want to run it a second time you can just type rsy
and then ↑ an it will complete to the last command that started with rsy. Another press of the uparrow will complete to the second-last and so on. I don't know why this isn't the default.
The default bashrc can be found in /etc/skel/.bashrc
. I would suggest you make a backup of your current bashrc, then replace your bashrc with the one in skel, then see if the problems still occur. Then if they don't, backup and edit your new bashrc, putting comments in saying what you did!!
Best Answer
Check out the available options to control history. I think you want
This is the default zsh setup, by the way.
You can save the history explicitly at any point with
fc -AI
and merge it back in withfc -RI
.