If you want to run a command without saving it in history, prepend it with an extra space
prompt$ echo saved
prompt$ echo not saved \
> # ^ extra space
For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run
To make this setting persistent, put it in your .bashrc.
With csh or any shell implementing csh-like history substitution (tcsh, bash, zsh):
Or Ctrl+P, Enter
Also, note that !! and !-1 will not auto-expand for you, until you execute them (when it might be too late).
If using bash, you can put bind Space:magic-space into ~/.bashrc, then pressing ...
reset or tput reset only does things to the terminal. The history is entirely managed by the shell, which remains unaffected.
history -c clears your history in the current shell. That's enough (but overkill) if you've just typed your password and haven't exited that shell or saved its history explicitly.
When you exit bash, the history is saved to the ...
This should be what you're looking for:
From man bash
If HISTFILE is unset, or if the history file is unwritable, the history is not saved.
Alternatively, if you want to toggle it off and then back on again, it may be easier to use set:
set +o history
set -o history
This is actually a really interesting behavior and I confess I have greatly underestimated the question at the beginning. But first the facts:
1. What works
The functionality can be achieved in several ways, though each works a bit differently. Note that, in each case, to have the history "transferred" to another terminal (updated), one has to press Enter ...
Bash maintains the list of commands internally in memory while it's running. They are written into .bash_history on exit:
When an interactive shell exits, the last $HISTSIZE lines are copied from the history list to the file named by $HISTFILE
If you want to force the command history to be written out, you can use the history -a command, which will:
You can use the !!:gs/search/replace/ notation to do what you want. This utilizes the global search & replace (:gs):
$ echo "harm warm swarm barm"
harm warm swarm barm
echo "horn worn sworn born"
horn worn sworn born
The Definitive Guide to Bash Command Line History
Caret search and replace in Bash shell
When you want bash to stop logging your commands, just unset the HISTFILE variable:
All further commands should then no longer be logged to .bash_history.
On the other hand, if you are actually supplying passwords as arguments to commands, you're already doing something wrong. .bash_history is not world-readable and therefore not the biggest ...
What you are looking for is CtrlR.
Type CtrlR and then type part of the command you want. Bash will display the first matching command. Keep typing CtrlR and bash will cycle through previous matching commands.
To search backwards in the history, type CtrlS instead. (If CtrlS doesn't work that way for you, that likely means that you need to disable XON/...
Yes, it's called "history expansion." See
LESS='+/^HISTORY EXPANSION' man bash
for full details.
Using an exclamation point followed by a number is arguably the simplest use:
However, you can also run the last executed command directly without knowing its history number:
Or you can run two commands back:
The form I most often use, ...
Zsh stores input lines (possibly with time information) in the file indicated by the variable HISTFILE. This should be an absolute file name (otherwise it will be interpreted relative to whatever directory is current at the time).
Zsh has no built-in default value for HISTFILE. The zsh distribution comes with a setup wizard for new users which has the value ...
You can use tput reset.
Besides reset and tput reset you can use following shell script.
echo -e \\033c
This sends control characters Esc-C to the console which resets the terminal.
Google Keywords: Linux Console Control Sequences
man console_codes says:
The sequence ESC c causes a terminal reset, which is what you want if
the screen is ...
To expand on what Gilles said, I have the following in my .inputrc to bind the up/down arrow key to history-search-backward and history-search-forward:
# Key bindings, up/down arrow searches through history
Just type something (...
Use \[...\] around the parts of PS1 that have length 0. It helps bash to get the length of the prompt right. Even with this measure, your command line can get spoiled when using multibyte characters (at least mine does). Hitting Ctrl+L also helps in such cases (but clears the screen at the same time).
Using Bash, I would just visit the directories:
$ cd /path/to/source/directory
$ cd /path/to/destination/directory
Then, I would use the shortcut ~-, which points to the previous directory:
$ cp -v ~-/file1.txt .
$ cp -v ~-/file2.txt .
$ cp -v ~-/file3.txt .
If one wants to visit directories in reverse order, then:
$ cp -v fileA.txt ~-
$ cp -v fileB.txt ...
!! is expanded by bash when you type it. It's not expanded by alias substitution.
You can use the history built-in to do the expansion:
alias sbb='sudo $(history -p !!)'
If the command is more than a simple command (e.g. it contains redirections or pipes), you need to invoke a shell under sudo:
alias sbb='sudo "$BASH" -c "$(history -p !!)"'
You can run bindkey with no arguments to get a list of existing bindings, eg:
# Enter vi mode
chopper:~> bindkey -v
# Search for history key bindings
chopper:~> bindkey | fgrep history
In emacs mode, the binding you want is history-incremental-...
You might want $HISTIGNORE: "A colon-separated list of patterns used to decide which command lines should be saved on the history list." This line in your ~/.bashrc should do the job:
HISTIGNORE='rm *:svn revert*'
Also, you can add a space at the beginning of a command to exclude it from history. This works as long as $HISTCONTROL contains ignorespace or ...
Command lines are not just available in history. They are also available, for example, in the output of ps -ocmd or through the /proc filesystem. (/proc/<pid>/cmdline) which is where ps reads them.
Also, users' home directories are often world- or group- readable; you can make the history file only user-readable, but that might not survive deletion ...
A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be saved. ...
If it refers to commands run just recently, a more efficient way is to reference them with negative numbers:
!-4; !-3; !-2; !-1
Also, once you do it, your last history entry will contain the whole chain of commands, so you can repeat it with !!.
If you haven't already, get familiar with the great builtin function fc, mentioned by Gilles. (Use help ...
Most shells that have a command line editing feature
support Emacs key bindings. (a tiny subset)
Alternatively, you could set up your shell to use vi command editing mode, by adding set -o vi to your shell startup file (e.g., ~/.bashrc).
Then, for example, ...
Basically, it's the last argument to the previous command.
!$ is the "end" of the previous command. Consider the following
example: We start by looking for a word in a file:
grep -i joe /some/long/directory/structure/user-lists/list-15
if joe is in that userlist, we want to remove him from it. We can either fire up vi with that long directory ...
With setopt histignorespace, the command is removed from the current session history. If you tested by pressing Up and seeing that the command line is still there, it's a feature.
Note that the command lingers in the internal history until the next command is entered before it vanishes, allowing you to briefly reuse or edit the line. If you want to ...