recall commands previously typed in a shell or other utility

learn more… | top users | synonyms

112
votes
10answers
30k views

Preserve bash history in multiple terminal windows

I consistently have more than one terminal open. Anywhere from two to ten, doing various bits and bobs. Now let's say I restart and open up another set of terminals. Some remember certain things, some ...
39
votes
12answers
6k views

best way to search my shell's history

Is there a better way to search my history file for a command than grep? I do have some idea what the command starts as, but I don't know how far back in the history it is. update: was formerly zsh ...
35
votes
4answers
4k views

Is there any way to keep a command from being added to your history?

Is there any way to keep a command from being added to your history? I have a command that I want to keep out of my history file, and I really don't care to have it there when I search the history ...
29
votes
12answers
1k views

How to quickly store and access often used commands?

I have a lot of commands I routinely need to execute, often with the slightest variation. Right now I'm storing them all in .bash_history and use CTRL-R to access them, but I wonder if there's a ...
25
votes
3answers
2k views

Why shouldn't someone use passwords in the command line?

Why do people fear writing passwords in the command line? The history file is located in ~/.history, so it's available only to the user who executed the commands (and root).
23
votes
1answer
5k views

How to Navigate within bash's Reverse Search?

Bash offers the functionality to reverse search via Ctrl + R. Then one can type in a part of a command it will show a fitting entry from the history. Assume this is my history: vim foo1 vim foo2 # I ...
22
votes
6answers
4k views

How do I close a terminal without saving the history?

More than once I've accidentally run a number of commands and polluted my bash history. How do I close my terminal without saving my bash history? I'm using Fedora.
18
votes
4answers
6k views

Command-line completion from command history

So, I've looked at history and at Ctrl+R, but they are not what I thought I knew. Is there a way that I can type in the beginning of a command, and cycle through the matches in my history with some ...
17
votes
5answers
1k views

In what situations would a user not let the shell record his command into history?

If I add export HISTCONTROL=ignorespace in .bashrc, bash won't record any commands which have whitespace before them into history. But I do not understand under what situations it will be useful. ...
17
votes
4answers
20k views

Understanding the exclamation mark (!) in bash

I used history | less to get the lines of previous commands and from the numbers on the left hand side I found the line I wanted repeated (eg. 22) and did !22 at the command prompt and it ...
17
votes
1answer
765 views

What does !$ mean?

I'm following through a tutorial and it mentions to run this command: sudo chmod 700 !$ I'm not familiar with !$. What does it mean?
17
votes
2answers
621 views

^x^y unix trick for all instances in last command?

One of my favorite Unix tricks is ^x^y, which will take the last command and replace the first instance of "x" with "y". However, I'm wondering if a similar trick works to replace all instances of "x" ...
16
votes
8answers
2k views

How do I repeat the last command without using the arrow keys?

I know I can use Up to iterate through previous commands. Running the last command simply involves Up + Enter. However, I was thinking of buying the Happy Hacking Keyboard as I spend a lot of time in ...
16
votes
4answers
992 views

Finding command execution time in hindsight

I've just executed a long-running process from the bash prompt. In hindsight, I wish I'd run time on it, or noted down the time at which I kicked it off. Is there any way of getting this information ...
16
votes
6answers
2k views

put history command onto command line without executing it

I use !n where (n) is the line number for executing a line in the history file I want executed at the command prompt which I find via history|less. But there is a command line history event I wish ...
16
votes
1answer
10k views

How to remove a single line from history?

I'm working in Mac OSX, so I guess I'm using bash...? Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?
15
votes
4answers
5k views

Bash history: “ignoredups” and “erasedups” setting conflict with common history across sessions

First of all, this is not a duplicate of any existing threads on SE. I have read these two threads (1st, 2nd) on better bash history, but none of the answers work - - I am on Fedora 15 by the way. I ...
14
votes
5answers
489 views

Use same arguments with different command [duplicate]

Here's something I find myself doing often: less super/long/file/name Followed by: vim super/long/file/name Is there an easy way to pass the args of the previous command over to the next? SO I'd ...
14
votes
3answers
2k views

Excluding some of the commands from being getting stored in bash history

Is there any way to exclude commands like rm -rf, svn revert from being getting stored in bash history? Actually I, by mistake, have issued them a number of times even though I have no intent to do, ...
14
votes
3answers
835 views

Where is bash's history stored?

If I run history, I can see my latest executed commands. But if I do tail -f $HISTFILE or tail -f ~/.bash_history, they do not get listed. Does the file get locked, is there a temporary location or ...
14
votes
1answer
738 views

How can I `alias sudo !!`?

I'm trying to set an alias for sudo !! in Bash. I tried alias sbb='sudo !!', but it interprets that as a literal !! and prints sudo: !!: command not found If I use double quotes, it substitutes ...
14
votes
2answers
341 views

bash_history: comment out dangerous commands: `#`

To prevent logging "dangerous" commands in bash history, I have added following line to my .bashrc file: HISTIGNORE='rm *:mv *:cp *:cat*>*:pv*>*' this works well, but it has a side effect: I ...
13
votes
1answer
4k views

How do I perform a reverse history search in ZSH's vi-mode?

I use vim for essentially all my editing needs, so I decided to once again try vi-mode for my shell (currently ZSH w/ oh-my-zsh on OS X), but I find myself trying (and failing) to use Ctrl-R ...
13
votes
3answers
467 views

Mangled history

In gui mode, when a user has more than one terminal open, how do the terminals rewrite the history file of that user? the reason I ask is because, it is quite possible that in each of the terminals ...
12
votes
2answers
3k views

How to execute consecutive command from history?

Suppose I want to execute a sequence of four commands that I have executed before. If the first one is 432 in the command-history, then I could do: $ !432; !433; !434; !435 I'm curious, is there a ...
11
votes
8answers
384 views

How to access the history on the fly in unix?

for example, if I do a mkdir thisismyfolder912 I remember there is some easier way to switch to thisismyfolder912 than having to do a cd thisismyfolder912 What is that way and how does it work? ...
11
votes
4answers
3k views

Temporarily suspend bash_history on a given shell?

Is there a way to temporarily suspend history tracking in bash, so as to enter a sort of "incognito" mode? I'm entering stuff into my terminal that I don't want recorded, sensitive financial info.
11
votes
2answers
590 views

Keep only successful commands in BASH history

Sometimes I misunderstand the syntax of a command: # mysql -d test mysql: unknown option '-d' # echo $? 2 I try again and get it right: # mysql --database test Welcome to the MySQL monitor. mysql ...
11
votes
1answer
204 views

Why is bash not storing commands that start with spaces?

If I perform a sequence of commands like: $ ls $ grep abc file.txt and then use the up arrow key to get the previous one, the terminal will show the last cmd (which is the grep here) But if I do ...
10
votes
4answers
665 views

Search for a previous command with the same prefix when I press Up at a shell prompt

Coming from a FreeBSD world I wish to make the Linux terminal behave like FreeBSD one, especially the 9.1 version, basically when you type cd in the terminal and push the "up" arrow you can browse all ...
9
votes
2answers
596 views

How to exit bash history search mode?

In Ubuntu 12.04 I use CTRL-R to enter a reverse history search. If the command I want is not found (after repeated CTRL-R), how do I immediately exit back to the (empty) command prompt with no ...
9
votes
2answers
1k views

How can I run a command in zsh without pushing it onto the current session's history?

Both bash and zsh support a shorthand of not placing a command in history if you prepend it with a space. This works great across sessions (if you've setopt histignorespace). However, the command is ...
9
votes
1answer
2k views

How to enable reverse search in zsh?

I recently switched to zsh (finally) and am loving it! So far one thing that I am missing is Ctrl+R to do incremental history search. I have the history set up properly HISTSIZE=10000 SAVEHIST=10000 ...
9
votes
1answer
6k views

Delete last N lines from bash history

When accidentally pasting a file into the shell it puts a ton of ugly nonsense entries in the bah history. Is there a clean way to remove those entries? Obviously I could close the shell and edit the ...
9
votes
1answer
861 views

Re-run multiple history commands

Imagine you've just run a dozen commands. Say... $ cd foo/ # history cmd #10000 (my history is very long) $ ... more commands ... $ cd ../ # history cmd #10012 I know I can re-run them ...
9
votes
3answers
4k views

How to properly escape exclamation points in bash?

Today, I was caught redhanded while attempting to code golf a password generator for Twitter. import string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9)) 90 chars. ...
9
votes
2answers
859 views

Command line prediction

I've found an interesting paper: Predicting UNIX Command Lines about command-line prediction (based on user past activity), and I wonder if any actual implementation of such thing exists?
8
votes
3answers
481 views

Execute a line of commands with one sudo

For example if I want to create a file and enter text in one line I can redirect the output into a file with the use of the > operator: echo "something" > /path/foobar but if I don't have ...
8
votes
3answers
2k views

How can I remove duplicates in my .bash_history, preserving order?

I really enjoying using control+r to recursively search my command history. I've found a few good options I like to use with it: # ignore duplicate commands, ignore commands starting with a space ...
8
votes
4answers
1k views

How can I save the last command to a file?

When I am running my analyses using the bash shell, I often want to save the commands I've used that gave me good results to a file in the same directory (my "LOGBOOK", as its called) so that I can ...
8
votes
3answers
2k views

Is there a maximum size to the bash history file?

Can I increase the size of the command history in bash? Note that I use a Red Hat Linux computer in the undergraduate astrophysics department here (so I don't get that many privileges).
8
votes
2answers
4k views

Why would anyone not set 'histappend' in bash?

After finding out what this shopt -s histappend means, it seems a very sane setting, and I'm surprised that it isn't default. Of course I may be shortsighted, so why would anyone not use such a ...
8
votes
4answers
1k views

Can I easily search my history across many screen windows?

My current screen session has 12 open windows on it. It's been running for weeks... I know I executed an ImageMagick convert command in one of these 12 screen windows sometime last week... is there ...
8
votes
1answer
787 views

What would cause vim not to retain command history?

On other distros I have run, vim remembers your command history even between sessions; this is especially handy when doing a lot of similar operations on different files. For some reason, it has been ...
8
votes
2answers
871 views

How can you log every command typed

How can you log every command someone has entered into the shell? I'm asking on both the basis of protecting yourself if you are logged into someone else's server and something breaks, or if someone ...
8
votes
1answer
754 views

Why is my bash prompt getting bugged when I browse the history?

Often when I start looking at history of commands some of the characters from a command displayed aren't erased, for example: What's happening: prompt$ some_command prompt$ some_commanother_command ...
8
votes
2answers
650 views

Saving bash history from multiple Konsole not working correctly

I use multiple Konsole terminals. And I want all the commands I type in every terminal to be saved in command history, so that next konsole i open will have all of them. To prevent each terminal from ...
7
votes
7answers
588 views

Find out what command I last ran that starts a certain way?

On bash commandline environment, you can do !! to rerun your last command. And you can press up arrow to see the the last command you ran. But what if you want to only see but not run the last command ...
7
votes
2answers
2k views

How to delete commands in history matching a given string?

I need to delete all commands in my history matching a string. I've tried: $ history | grep searchstring | cut -d" " -f2 | history -d -bash: history: -d: option requires an argument $ history | grep ...
7
votes
3answers
2k views

ZSH: search history on up and down keys?

Currently, I have the following in my .zshrc: bindkey '^[[A' up-line-or-search bindkey '^[[B' down-line-or-search However, this only seems to match the content of my current input before a space ...