LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   bash history wrap around to the first command (https://www.linuxquestions.org/questions/linux-software-2/bash-history-wrap-around-to-the-first-command-4175679980/)

BudiKusasi 08-05-2020 11:06 PM

bash history wrap around to the first command
 
How do we have bash history wrap around to the first, oldest command when at the latest, newest command?

scasey 08-05-2020 11:56 PM

Um
Code:

history | more
??

berndbausch 08-06-2020 01:17 AM

What do you mean by "history wrap around"? History is in a file, normally $HOME/.bash_history, and has a first command and a last command.

Do you mean a command that goes back in history and, when it reaches the first line, goes to the last?

By default, history viewing and editing uses emacs commands. Try to find what you want in the emacs manual. You can also use vi as the history editor (set -o vi).

However, I doubt that either emacs or vi have cursor movement commands that wrap around.

I am curious - why do you need this feature?

shruggy 08-06-2020 02:18 AM

Not the answer to your question, but I use HSTR to navigate bash history.

rnturn 08-06-2020 03:40 PM

Quote:

Originally Posted by berndbausch (Post 6153112)
However, I doubt that either emacs or vi have cursor movement commands that wrap around.

Normally, "^r" (reverse search) at the command line will search backwards in the history file for a given command/string. In Emacs itself, "^r" will wrap around when reaching the beginning of the file and resume searching at the end. However, it does not wrap around the beginning/end of the command line history---at least it doesn't the way my environment is set up.

frankbell 08-06-2020 07:40 PM

This thread from Stack Exchange might help: https://unix.stackexchange.com/quest...search-in-bash


All times are GMT -5. The time now is 06:06 PM.