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
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.
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 ...
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 ...
53
votes
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 ...
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 ...
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, ...
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 ...
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 ...
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 (:...
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 ...
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)
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 :)
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 (...
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:...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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, ...
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.
...
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 ...
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 ...
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-...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
command-history × 757bash × 453
zsh × 155
shell × 103
command-line × 73
linux × 34
terminal × 28
shell-script × 25
history-expansion × 25
oh-my-zsh × 21
ksh × 18
macos × 17
alias × 15
tcsh × 14
line-editor × 14
prompt × 13
readline × 13
logs × 12
debian × 11
ssh × 9
grep × 9
keyboard-shortcuts × 9
command × 9
autocomplete × 9
search × 9