recall commands previously typed in a shell or other utility

learn more… | top users | synonyms

8
votes
3answers
26k views

How do I clear the terminal History?

I am using Linux Mint 17.1 Rebecca for about 2 days and accidentally typed my password into the terminal which is now displayed in the history list of commands I have previously typed. I want to ...
3
votes
2answers
44 views

Protect session log from being written again by anyone

We have implemented a workaround to save command history in a new file for each user session for audit purpose. So each session file is identified by the start time and the username. The problem: The ...
0
votes
0answers
19 views

How do I merge command histories from different terminals? [duplicate]

I have one terminal in which the history looks like: 179 wget https://github.com/SIPp/sipp/archive/v3.5.1.tar.gz 180* tar -xzvf v3.5.1.tar.gz 181 ls 182 cd sipp-3.5.1/ 183 ./configure --...
6
votes
6answers
9k views

History command inside bash script

I have been bashing my head to write a simple history script for the last two days. History is a shell-built in command I couldn't able to use that within a BASH script. So, Is there a way attain this ...
1
vote
1answer
52 views

How to get second to last parameter of previous command in bash?

I can use Esc+. to get the last parameter of the previous command, but is there an equally convenient short-cut to get the second to last parameter?
0
votes
1answer
29 views

HISTFILE env var unset within programs. Can I access it in any way? [duplicate]

When I try to access the "HISTFILE" env var within a program, it isn't there $ echo $HISTFILE /Users/drewgross/.bash_history $ python Python 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 ...
2
votes
1answer
55 views

Change the key that show previous command lines in ksh

In most shells on Linux, when you press the Up-arrow key, it shows the previous command lines from the command line history. My question is, for the ksh shell, How do I set up some other key so ...
35
votes
5answers
11k 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 ...
3
votes
1answer
31 views

Exit status of fc -e is the wrong way around

I'm trying to edit and recall a previous command with Bash's built-in fc command, but somehow the exit status indicates failure on successful edit, even if that is a no-op. Demo: $ uname Linux $ fc -...
2
votes
1answer
2k views

How to check the time at which the command was executed?

When history command is executed, it shows a list of recently executed commands. Is there any provision with which we can see the time at which those particular commands were executed?
4
votes
1answer
46 views

How do I search bash's history in vi mode for “foo.*bar”

I have my bash environment in vi mode (set -o vi). So I can type <ESC>/ followed by a word, followed by enter, and bash searches for the word in the history. Since / is also vi's method to ...
0
votes
2answers
98 views

How do I record all terminal input and output to a local file by default for each session?

I'm aware the script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my ...
2
votes
3answers
258 views

Hide ones command history from other users on a Linux server

When I log in via ssh on a Linux(Ubuntu) server, I notice that all the bash commands executed by other users on the server are saved in the command history. Is there a way that could allow me to hide ...
0
votes
1answer
46 views

Up arrow at an empty prompt in ksh93

This is a request for explanation or pointer to documentation. I'm a KornShell93 (ksh on Mac OS X or ksh93 elsewhere) user. I like the shell for its relative simplicity as an interactive shell and ...
3
votes
2answers
39 views

Is there a shortcut to rerun a command with arguments from last command (not cd, ls or echo)

Searching through passed Logfile with something like this: cat /path/to/logfile | grep -iEw 'some-ip-address-here|correspondig-mac-adress-here' This gives me all the passed log lines until now so ...
12
votes
2answers
464 views

View a range of bash history

The history command lists out all the history for the current session. Like: 1 ls 2 cd /root 3 mkdir something 4 cd something 5 touch afile 6 ls 7 cd .. 8 rm something/afile 9 cd .. 10 ls 11 history ...
7
votes
6answers
3k views
3
votes
2answers
173 views

Can I delete .bash_history without sudo?

I don't want it to do it to my system, but I am wondering, is it possible to delete .bash_history? And if yes, then can you bring it up again or there will be no history ever again? Also, is the ...
3
votes
1answer
125 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 ...
18
votes
7answers
1k views

Search for a previous command with the prefix I just typed

We can use up and down arrow to navigate in command history. In some IDE, such as matlab, if we input sth and then press the arrow keys, we stroll among only the history commands starting with what ...
7
votes
4answers
188 views

Simplest standard way to print last bash command with timestamp

I would like to print last bash command with its timestamp. history 1 shows the history command itself. I need to use it on many machines, so it should not depend on any custom configuration. There ...
1
vote
1answer
26 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: ...
6
votes
4answers
4k views

How can I recall a numbered history command for edit?

I frequently search for changes with history | grep 'string' I get a list of commands in my history, along with the history line number), e.g. history | grep 'git' 755 git status 1535 git push ...
7
votes
1answer
6k 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
1answer
40 views

How do we know a particular command was executed by whom?

I want to know which user has executed rm command in production server?
0
votes
1answer
30 views

how to make sure csh won't mess up your tcsh history timestamps?

I use tcsh as my default shell. Sometimes, I run csh (e.g., for testing), and it messes up my savehist history file, particularly, the timestamps -- lots of events end up appearing under the exact ...
3
votes
1answer
56 views

Scroll to the last command on Terminal? (like OS X Terminal marks)

Mac OS X Terminal marks are incredibly useful. For example, when I type a command that echoes a lot output, it's easy to read the beginning with Cmd+Up. It will scroll to the last command and ...
4
votes
2answers
66 views

sometimes history commands are not stored in .bash_history

I issued many commands yesterday in my CentOS 7. But when I wanted to retrieve these commands today, I found there was no any record. When I opened the file .bash_history, I still could not find the ...
2
votes
2answers
43 views

Use previous “path” in a command [duplicate]

A couple of years ago, a former coworker told me a trick in Bash that I completely forgot how to do it. The idea is that when you type a path, in the next command you can use some shortcut to ...
0
votes
1answer
29 views

How to prevent .bash_history from being used to rebuild history

We use custom history files which get backed up per user. When someone does a history -c we notice that after they log back in there is history in the buffer again and it seems to come from /root/....
16
votes
4answers
5k 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 ...
2
votes
1answer
41 views

zsh tcsh-like history navigation

In tcsh, the \eP and \eN commands take into account the whitespace-normalized prefix of the current line, not just the first word. For instance if my history contains git pull upstream feature-...
3
votes
1answer
68 views

What does !# (exclamation hash), !$:r:r (exclamation dollar colon r), !#:t (exclamation hash colon t) mean in the below bash commands?

I have been trying to install a Nagios package and stumbled upon these weird bash expansions on a guide here. Can someone help me understand what do the expansions mean? A wiki link would also be ...
0
votes
1answer
44 views

Why there isn't a number of the command and a timestamp for fish?

In fish, when I type history | less I see the following for example: history | less export HISTTIMEFORMAT="%h/%d - %H:%M:%S " bash in bash I see this: 491 18/04/16 14:31:02 cd 492 18/04/16 ...
3
votes
3answers
238 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 ...
1
vote
1answer
59 views

Commands pasted into bash not recorded in history [duplicate]

From time to time I find that when I copy/paste a command from a web page (or from the Terminal window itself) the pasted command is not recorded in bash history. For example, just now I did this: cd ...
18
votes
5answers
9k 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
39 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
27 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 space-...
5
votes
1answer
112 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
82 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
511 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
3answers
777 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 (...
7
votes
3answers
554 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
509 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 ...
27
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
179 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
20k 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
335 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 ...