Skip to main content
122 votes
Accepted

View a range of bash history

Instead of history, you can use fc, which allow you select range: fc -l 4 7
cuonglm's user avatar
  • 155k
97 votes
Accepted

With BASH after "scrolling" up to a previous command... how to then move on to the next in this history?

Running the command with Ctrl+o instead of Enter will run a command from history and then queue up the next one instead of returning to the front of the bash history.
Jon Reinhold's user avatar
84 votes

history isn't preserved in zsh

Bash and zsh have different defaults. Zsh doesn't save the history to a file by default. When you run zsh without a configuration file, it displays a configuration interface. In this configuration ...
Gilles 'SO- stop being evil''s user avatar
55 votes

How do I clear the terminal History?

I have tried history -c but the history comes back once we exit and reopens.This helped me. cat /dev/null > ~/.bash_history && history -c && exit This clears the history saved in ...
athul's user avatar
  • 691
53 votes

How to clear history in zsh

The equivalent to history -c on zsh is history -p
Potato Boii's user avatar
47 votes

history isn't preserved in zsh

While the existing answer is correct, I thought it might be worth adding that there's possibly a better option than appendhistory for saving your history and this is SHARE_HISTORY. From the docs ...
bert's user avatar
  • 643
43 votes

Allowing comments in interactive zsh commands

$ setopt interactive_comments $ echo hello # comment hello By default, the zsh shell enables the interactive_comments shell option in scripts (non-interactive shells in general), but not when running ...
Kusalananda's user avatar
  • 339k
35 votes
Accepted

How does !! work in bash?

!! is listed in the bash manual under the heading "Event Designators": An event designator is a reference to a command line entry in the history list. Unless the reference is absolute, ...
Kusalananda's user avatar
  • 339k
31 votes

Why do I lose my ZSH history?

ZSH History file can be truncated/lost/cleaned for multiple reasons those can be: Corruption of the zsh history file (because of a power-cut/system-fail while a shell is opened, in this case fsck ...
intika's user avatar
  • 14.6k
30 votes
Accepted

How to clear history in zsh

To get an empty history, temporarily set HISTSIZE to zero. function erase_history { local HISTSIZE=0; } erase_history If you want to erase the new history from this shell instance but keep the old ...
Gilles 'SO- stop being evil''s user avatar
28 votes
Accepted

Does a shortcut for executing a series of commands in bash history exist?

EDIT: You can do this in POSIX-compliant fashion with the fix command tool fc: fc 77 79 This will open your editor (probably vi) with commands 77 through 79 in the buffer. When you save and exit (:...
Wildcard's user avatar
  • 36.8k
27 votes

Why do I have duplicates in my zsh history?

Add the following lines to your ~/.zshrc file to avoid duplicates in history setopt HIST_EXPIRE_DUPS_FIRST setopt HIST_IGNORE_DUPS setopt HIST_IGNORE_ALL_DUPS setopt HIST_IGNORE_SPACE setopt ...
VVK's user avatar
  • 387
26 votes

How do I clear the terminal History?

Instead of removing all your history entries, type these commands in your terminal: history -c (for delete history) history -w (save history)
user171143's user avatar
25 votes

How to view datetime stamp for history command in Zsh shell

history -E or history -i or whatever DO NOT work for me. zsh --version shows that zsh 4.3.6 (x86_64-suse-linux-gnu). Then fc -li 100 works! It shows the recent 100 commands with timestamp :)
Gab是好人's user avatar
25 votes
Accepted

How do I input n repetitions of a digit in bash, interactively

Try echo Alt+1Alt+6Ctrl+V0 That's 6 key strokes (assuming a US/UK QWERTY keyboard at least) to insert those 16 zeros (you can hold Alt for both 1 and 6). You could also use the standard vi mode (...
Stéphane Chazelas's user avatar
23 votes
Accepted

Zsh: make the up arrow skip identical commands

For zsh put this in your configuration: setopt histignoredups What it does, it will ignore duplicated history entries during search. The equivalent setting for bash is HISTCONTROL=$HISTCONTROL:...
Martin Sugioarto's user avatar
23 votes

Is history expansion disabled in scripts?

Yes, history expansion is enabled by default only for interactive shells. To enable it for a shell script, write: set -H To disable it in an interactive shell, write: set +H To determine whether ...
Wildcard's user avatar
  • 36.8k
21 votes

How to remove a single line from history?

Zsh on Mac If you are using Zsh, history -d linenumber doesn't work to delete a specific line number in the command line history. However you can edit the history file. Close and reopen your terminal ...
Suragch's user avatar
  • 361
21 votes
Accepted

sometimes history commands are not stored in .bash_history

The most likely cause for history items not to show up is not by setting HISTFILE to nothing or HISTSIZE to zero, it is by logging into the same machine twice and exiting with the second bash instance ...
Anthon's user avatar
  • 79.9k
20 votes

read with history

To copy Mike Stroyan's great answer from this old mailing list post: You can use "history -r" to read a file into the shell's history and "history -s" to add each line that you read into the ...
Chris Pacejo's user avatar
20 votes

View a range of bash history

If you must use history command, pipe it through sed or awk: history | sed -n '10,20p' history | awk 'NR >= 10 && NR <= 20' Otherwise cuonglm's answer is better option.
G.Gabunia's user avatar
  • 301
20 votes
Accepted

Zsh: can I have a combined history for all of my shells

First, by default, zsh doesn't save the command history. You need to set HISTFILE to the path to the file where you want to save the history and SAVEHIST to the number of lines you want to save. See ...
Gilles 'SO- stop being evil''s user avatar
19 votes
Accepted

How to stop bash editing the history when I reuse and modify an entry?

Turns out revert-all-at-newline is the answer. I needed to include set revert-all-at-newline on in my ~/.inputrc file, since using the set command at the bash prompt had no effect. (Then, of course, ...
IpsRich's user avatar
  • 767
19 votes

Unlimited history in zsh

I was having a problem with history being capped at 10000 until I realized oh-my-zsh was setting its own HISTSIZE and SAVEHIST values. TL;DR, make sure to put the lines at the bottom of your .zshrc. ...
Matthew D. Scholefield's user avatar
19 votes

With BASH after "scrolling" up to a previous command... how to then move on to the next in this history?

Jon Reinhold's answer is great, but there's is a much more powerful solution that I'll suggest. I also have a comment about a gotcha in Jon's answer, but I don't have enough reputation to be able to ...
user1404316's user avatar
  • 3,098
18 votes

Temporarily disable history in zsh

Launch a new zsh shell and disable history within it. Option 1 zsh # or just `$SHELL` if you're already running zsh unset HISTFILE ...secret commands... exit The secret commands won't be stored in ...
Totor's user avatar
  • 20.3k
16 votes

ZSH: search history on up and down keys?

This blog post from 2013 recommends a couple of keybinds that match all the words before the cursor. # Cycle through history based on characters already typed on the line autoload -U up-line-or-...
joeytwiddle's user avatar
  • 1,038

Only top scored, non community-wiki answers of a minimum length are eligible