recall commands previously typed in a shell or other utility

learn more… | top users | synonyms

17
votes
5answers
7k views

How can I search history with what is already entered at the prompt in zsh?

In zsh, I know that I can search history with Ctrl+r. However, oftentimes I start to type a command directly at the prompt, but then realize I should be searching history. When I hit Ctrl+r, it brings ...
4
votes
1answer
36 views

What does the history command !# do?

From the manual pages on history: Event Designators An event designator is a reference to a command line entry in the his‐ tory list. Unless the reference is absolute, ...
1
vote
1answer
25 views

How do I both censor a command away from .bash_history and also be able to return to it with up arrow?

When one prepends a space character to the command, it disappears from history. But this also causes the command to no not easily editable and re-runnable. How do I make weaker version of ...
5
votes
1answer
20 views

Clear recent open file history on Linux Mint

Sometimes others in my household briefly use my computer, when they do I sometimes don't want them to see my file history. I know how to prevent Bash from writing entries to the ~/.bash_history file ...
0
votes
1answer
34 views

Create HISTFILE in subshell

Here is my HISTFILE: $ echo $HISTFILE /home/Steven/.bash_history I can create it by using exit: $ [ -e $HISTFILE ]; echo $? 1 $ exit $ [ -e $HISTFILE ]; echo $? 0 However if I exit a subshell, ...
0
votes
0answers
13 views

searching through command line history [duplicate]

I use reverse search when looking for a particular command on the command line by pressing CTRL + R. That returns the first command it finds in reverse order. To go back to the next further command I ...
2
votes
1answer
502 views

How to use history commands with readonly PROMPT_COMMAND?

I'm sometimes logged in on a host which I do not control and where PROMPT_COMMAND is readonly. Is there some way to work around this to run history commands anyway, for example using PS1? I've tried ...
2
votes
2answers
132 views

fish: sudo: !!: command not found

I have fish installed in my Linux Mint DE. I really like how fish makes things easier and it looks so pretty although I haven't find a correct answer about why I can't execute: sudo: !!: command not ...
2
votes
3answers
728 views

Why can't Korn Shell do ctrl-r?

If I use PC-BSD with the default shell (Korn) then Ctrl+r doesn't work. Why won't it work? Ctrl-r was introduced to search your history in the late 1970s or early 80s and my BSD still can't do it ...
1
vote
0answers
95 views

Why does history not overwrite but append when histappend is set to off in Bash?

Several days ago, I had one Terminal tab doing ssh, and the other doing a lot of work locally. And then I restarted the machine (on a Mac with Mavericks). When I ran Terminal again, I found that all ...
7
votes
3answers
524 views

Per-directory history in zsh

I am happily using zsh since a while now, and I am quite satisfied with my history settings, which are: # Write to history immediately setopt inc_append_history # History shared among terminals ...
9
votes
4answers
409 views

Keeping history per working directory (cf. per shell session)

Is there a way to make a modern shell's history feature be scoped to a path? My working contexts are split up as paths on the file system, and the pattern of shell activity, such as repeatedly issued ...
26
votes
4answers
2k views

Is there any way to execute commands from history?

For example: [root@ip-10-0-7-125 ~]# history | grep free 594 free -m 634 free -m | xargs | awk '{print "free/total memory" $17 " / " $ 8}' 635 free -m 636 free -m | xargs | awk '{print ...
1
vote
2answers
166 views

Specifying numeric ranges in zsh history

According to the docs I can tell the zsh history to print lines in a range. The docs say "history [first [last]]" I've tried "history a b" but that gives a too many arguments error. I've also tried ...
22
votes
2answers
19k 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 bash history. Is there a clean way to remove those entries? Obviously I could close the shell and edit the ...
1
vote
3answers
59 views

Unlimited history in zsh

In zsh, I want to have unlimited history. I set HISTSIZE=, which works in bash. Now I import an old history mv old_history .history which is pretty big wc -l .history 43562 .history If I now ...
1
vote
1answer
79 views

timestamp saved history file

I've seen a lot of documentation on how to timestamp the output of the history command. But how would you go about time-stamping a saved history file? For example I have a server setup to save each ...
29
votes
2answers
9k 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 ...
1
vote
2answers
98 views

.bash_history keeps truncating

My .bash_history keeps truncating even though I set: export HISTSIZE= export HISTFILESIZE= On my .bash_profile. Im not sure when it happens but it might happen when I logout or shut down my ...
34
votes
5answers
9k 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 ...
0
votes
1answer
35 views

How can I access the history buffer in sh? (not in Bash)

Is there a command history in sh, for example how to access it, and as well, how to ensure it is clear? To clarify shells here: let's say you've logged on to a non-Gui Linux system, and $SHELL is ...
22
votes
8answers
1k views

Clipboard for copying and pasting files in command line?

In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it ...
0
votes
1answer
19 views

How to increase history in oh-my-zsh?

I just installed oh-my-zsh for the first time. I just want to know how can I modify the number of past commands that are remembered in history? Where can I set this setting?
4
votes
5answers
1k views

How can I do the `history` command and not have line numbers so I can copy multiple line commands?

Sometimes I do the history command so I can see 4 commands in a row. I want to copy those commands so I can run them again. I usually select them with the mouse and shift-ctrl-c which works ok, but ...
1
vote
1answer
59 views

how to save a command in bash history without executing it programmatically?

I have a docker container and every time I build and start it, I want just to press UP for choosing a predefined command. What's the best way to handle this?
1
vote
1answer
34 views

Duplicates in bash history

I have the following in my ~/.bashrc HISTCONTROL=ignoreboth:erasedups However my history contains many duplicates e.g. I have 5 entries for sudo apt-get upgrade. I am running Raspbian Jessie and ...
2
votes
1answer
51 views

Search bash history for already typed command

When I type ctrl+r and then start typing I can see what commands in the history match which is great. Now is there a way to search the history on commands I have already typed in the terminal? For ...
48
votes
4answers
47k 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?
1
vote
1answer
67 views

zsh HISTFILE - still read from ~/.zsh_history

I set my $HISTFILE env var to something custom, and my zsh is indeed writing to the new histfile. But when using up-arrow or other history-searching capabilities, it still reads from ~/.zsh_history. ...
20
votes
5answers
7k 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 ...
7
votes
1answer
5k views

how to enable command history of shell

I am using ubuntu 13.04, in this the command history of the shell is getting erased on close. Can someone tell me how to prevent this from happening?
1
vote
0answers
24 views

history shows only current session

This is what I see in my terminal in a fresh session: Agent pid 6847 Identity added: /home/eric/.ssh/id_rsa (/home/eric/.ssh/id_rsa) ➜ ~ history 1 history ➜ ~ I'm using Linux Mint 17.3 ...
14
votes
3answers
1k 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 ...
8
votes
2answers
294 views

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

Some instances of bash change the command history when you re-use and edit a previous command, others apparently don't. I've been searching and searching but can't find anything that says how to ...
36
votes
4answers
39k 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 ...
0
votes
0answers
18 views

Can I make history not print any timestamps for commands that were run before I enabled that option?

If you run history, it outputs the current date before commands that were run before I enabled timestamps, is there anyway I can make it ignore that? For example, if my .bash_history looks like this: ...
1
vote
0answers
33 views

Can I prevent zsh slowing with a large history?

I've just migrated from bash to zsh. I converted ~/.bash_history for use in zsh. It's 150 000 lines long. bash is almost instantaneous to start up, but zsh is now fairly slow, taking half a second to ...
1
vote
1answer
98 views

Implement a shell in a bash script [closed]

I am trying to emulate a shell in a bash script, like this: cmd_shell() { while true; do read -e -p 'pass> ' command run_cmd $command done } It works ok, and the option ...
1
vote
2answers
69 views

How to get the previously used command in HP-UX reverse search

I'm using HP-UX OS and want to use previously typed command, as how I'm using in Linux Ctrl+r for ease access in the HP-UX command line.
3
votes
4answers
73 views

Sticky entries in shell history

Is there a way one could make some commands "sticky" in a shell history? I want to save some favourite commands that would be searchable with Ctrl+R, like the rest of the history, but they should ...
0
votes
1answer
44 views

bash-like last command in history using up-down arrow keys in zsh [duplicate]

In bash, we can use the up and down arrow keys to get the last or nth previous command in history. Can we do this in zsh?
21
votes
2answers
899 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?
1
vote
2answers
98 views

Echo & redirect bash history !commands to file

Is it possible to echo and redirect history commands into a script file by the ! command? Is there variation of the pipe, redirect, or tee commands I am overlooking? 518 xmodmap -e "keycode 66 = ...
0
votes
0answers
23 views

Linux Bash History - eliminate/stop specific command from being stored in history [duplicate]

I have shared history (very large history too) setup in my .bashrc file (see below for my .bashrc). I also have PRTG monitoring (uptime monitoring and graphing, like MRTG) of my many linux/centos ...
5
votes
5answers
1k views

Where is the log of used commands in Linux?

In Linux, generally we use a lot of commands and it is difficult to remember all of them. history command provides the list of commands we used previously but its limit is less. New commands are ...
1
vote
0answers
39 views

Variables in history?

Is it possible to include environment variables in the history output. Something along the lines of: %T %F $SUDO_USER $HISTORY_COMMAND 1 2015-01-01 00:00:00 USER123 echo 123 Reason being we have a ...
8
votes
4answers
4k 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 ...
30
votes
4answers
13k 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.
1
vote
1answer
28 views

Is there any way to list the latest GUI transactions in Linux?

Suppose that I've moved a directory in my Xfc desktop in another directory, which I can't remember the name of the destination directory. Is there any way to list the latest transactions in ...
0
votes
0answers
20 views

How to remove duplicate entries from bash history? [duplicate]

I have set: $ echo $HISTCONTROL ignoreboth:erasedups and expected by the value of erasedups for all my duplicates entries to disappear from my bash history. Yet when calling cd a few time, I still ...