recall commands previously typed in a shell or other utility

learn more… | top users | synonyms

1
vote
2answers
125 views

Write bash_history to a file with a timestamp

I need help with the script below. The requirement is to capture command line history in a file with specific date and time of commands, when they were executed. The below script captures history ...
193
votes
13answers
56k 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 ...
2
votes
1answer
17 views

How to cancel and keep reverse-i-search?

Often I fail to find something with reverse-i-search but want to keep what I have already written. For example, typing pdflatex fails to complete to pdflatex mydocument.tex. If I then cancel it with ...
8
votes
4answers
3k 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 ...
42
votes
13answers
13k 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 ...
1
vote
1answer
112 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 ...
1
vote
1answer
53 views

Detailed history of all commands/actions (also in GUI)

The famous history command shows us a list of recently executed commands. If we set the HISTTIMEFORMAT variable we can also see when the commands where executed. I would like a more general version of ...
2
votes
3answers
341 views

How to set the number of commands history recalls

I am using bash. To browse my command history I am calling the history command which I believe is calling the Gnu program of the same name. (I don't know if there's a better bash specific way). In ...
1
vote
1answer
554 views

How would you get all users history

I know there is the $HISTFILE variable where i can find the currently logged in users history-file, but how can i be sure to get every history file on the server I was thinking of the ...
0
votes
1answer
37 views

Sourcing a redistributable script by default

I am creating a bash script which I wish to release on github. The script needs to access the command history but this is not possible without sourcing that script. I don't want users to put it in ...
2
votes
1answer
40 views

Why do I get different results with the same user and the history command?

I work with Linux for quite some time and have seen this behaviour but I never got a good explanation. Probably it's even very simple. If I login twice with the same user (bash) in the same server ...
19
votes
2answers
822 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
1answer
68 views

Using only in-memory command history

How can I prevent Bash from writing history entries to disk? My ~/.bashrccontains the line trap 'unset HISTFILE; exit' SIGHUP but it doesn't have the desired effect. If I run history -c && ...
10
votes
2answers
435 views

Expand subshell before executing it?

I often run commands using subshells, and sometimes would like to have the subshells expanded before I run something.. This way I could verify what I'm doing, and possibly edit what's about to happen ...
1
vote
1answer
37 views

Is it possible to get working history for multi-line commands in mksh, using vi editing mode?

On my Debian systems, I have always used pdksh as my interactive shell. Originally, command-line history behavior was similar to what I grew up with on platforms like AIX and Solaris. Recently, ...
1
vote
2answers
94 views

Bash - incremental history search (ctrl+r) - matching multiple non-adjacent words

When using Ctrl+R to search bash history, is there some way to match two words that aren't next to each other. For example, let's say I wanted to find the last command that contained httpd and awk ...
4
votes
1answer
55 views

Search history from multiple bash session only when Ctrl + R is used, not when arrow keys are used

I usually have multiple bash sessions open. I want the history from multiple session to appear when doing a search (with Ctrl + R). When arrow keys are used only the current bash session's history ...
16
votes
1answer
13k 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 ...
1
vote
1answer
71 views

How to get last N commands from history?

I want to see what are the last N commands in my history. I thought history | tail -n 5 would make it, but I noticed that a multiline command counts for as many lines as it has. $ echo "hello how are ...
13
votes
1answer
201 views

Update bash history on others terminals on exit of one

I know this question has a similar interpretation, as its asked here keep updating (and duplicated here). But what I'm trying to achieve is a bit different. I don't like the idea of my prompt ...
6
votes
1answer
284 views

read with history

How can I make the builtin read command support history, by pressing the up/down key to cycle through them? I've tried catching when you press the up key, however it doesn't seem to work with read: ...
3
votes
2answers
3k views

Tab autocompletion and history in tcsh

I use tcsh, and I'd like to set up the following behaviour, which I've seen on some systems in the past. If I type !string TAB then: If the history contains a unique entry beginning with string, ...
39
votes
3answers
2k views

How do I open an incognito bash session?

Is it possible to open an incognito session in bash? For example, when we need to enter passwords in commands and don't want bash to add them to history.
4
votes
2answers
279 views

Is there any way to undo a bash history modification?

By pressing up, I can go through previously entered commands. I've noticed though that if I modify one of them, that alters the history. For instance, if I type: echo a echo b echo c ...
3
votes
2answers
780 views

How to stop bash replacing commands in history with asterisks ? (‘*’)

I have some commands replaced with * in the bash history, e.g. 1094 apt-get update 1095* 1096 dpkg -i /var/cache/apt/archives/libssl1.0.0_1.0.0h-1_amd64.deb How to prevent this?
2
votes
5answers
161 views

Bash and its exclamation mark command, preview actual command before executing it?

! as a prefix to some string will execute whatever command in the command buffer that starts with the (partial) string given. There are also some other uses for it. See e.g. Understanding the ...
1
vote
1answer
44 views

How to exclude command from history list, but to keep it in “live” history?

I've meanwhile managed to keep my history a lot cleaner thanks to you guys' great tips involving the HISTIGNORE option in .bashrc, omitting all those pointless ll or df -k lines. However, I've ...
0
votes
1answer
106 views

How to implement command history in Linux terminal?

I am using Putty as Terminal to connect a Linux server running Oracle Linux. To use a command multiple times, I have to type that command each time. There is no function of Up and Down button unlike ...
1
vote
3answers
324 views

how to record all who that login to my linux machines and records them

I installed the package audit on my linux red-hat 6.x machine in order to view the recored of each user that log to my linux machine yum install audit kit installation from: ...
1
vote
1answer
65 views

Recover deleted commands from history?

If someone were to delete commands from the shells history, is there any way to recover those deleted commands in Linux?
5
votes
3answers
1k views

“history” stops working when run inside bash script

I am writing a simple script to grep my bash history to find a particular string. On the command line, I can do the following, which works fine: history | grep git However, when I create a bash ...
2
votes
1answer
27 views

repeat bash history expansion substitution for all the matches

:& repeats bash history expansion substitution. For example: $ echo 1 1 1 1 1 1 1 1 1 1 $ ^1^9 echo 9 1 1 1 1 9 1 1 1 1 $ echo 1 1 1 1 1 1 1 1 1 1 $ ^1^9^:& echo 9 9 1 1 1 9 9 1 1 1 $ echo 1 ...
2
votes
1answer
63 views

Is it possible to track bash commands in real time?

I'd like to know if I can track commands entered by user in a bash shell, in real time. What I'm trying to do is something similar to thefuck, but I need to prompt the user as and when he enters new ...
2
votes
3answers
38 views

reuse the last command output at the given index/line-num

ls displays: entry1 entry2 entry3 How can I reuse the above output (not all of the entries but the entry at a given line, say n) in the next shell command? Something like: vi $(!!)@3 Must ...
1
vote
0answers
20 views

Cross-session duplicate removal in bash command history

The problem context: always active ignoreboth and erasedups HIST_SIZE and FILESIZE with desired/practical limits of different history lines for our user almost always have multiple parallel sessions ...
28
votes
4answers
12k 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 ...
5
votes
1answer
106 views

Bash: “history number” vs “command number”

While Googling how to customize my shell prompt via the PS1 variable, I'm seeing tables of special characters that can be used. In particular: \! the history number of this command ...
2
votes
1answer
136 views

move back to the end of bash history when using reverse search?

I keep fairly long bash history and sometimes when I search for something with bash reverse search function(Ctrl+r) I end up at the beginning of search history and I still did not find what I needed ...
7
votes
2answers
148 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 ...
0
votes
0answers
19 views

How can I copy the previous argument for the *current* command? [duplicate]

I can use Alt+. or !$ to get the last argument passed to the previous command, however, is it possible to get the last argument passed to the current command? For example, something that I do ...
0
votes
1answer
45 views

Persistent Bash history between detached processes

I haven't yet been able to find this among the Bash documentation so I was hoping it could get answered if I asked it here. Is there any way that I can, on execution of a script, branch its history ...
7
votes
3answers
6k views

Why does the exclamation mark `!` sometimes upset bash?

I realize that ! has special significance on the commandline in the context of the commandline history, but aside from that, in a runing script the exclamation mark can sometimes cause a parsing ...
2
votes
1answer
147 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 ...
1
vote
0answers
61 views

Why can I change bash history?

Why does bash change the history even I'm not executing a command I'm modifying? For example, if I type: $ echo foo1 foo1 $ echo foo2 foo2 $ echo foo3 foo3 After this, I press up twice, and I get ...
5
votes
3answers
572 views

Search commands in history with discontinuous keywords

I was wondering how to search commands in history without knowing the first few letters of the command? When searching using Ctrl-R in bash, one has to give the first few letter of the command. ...
0
votes
1answer
17 views

Getting the starting position in the history that will be appended to the history file (not read from the file or previously written)

I'm trying to write functions to remove some history lines using history -d before it is written to the file, while leaving them usable in the shell itself. But apparently this command will not ...
5
votes
3answers
111 views

How to undo changes in the commands-history?

In UNIX systems you can press top and bottom arrows to navigate through the previous commands. This is extremely handy. Sometimes, I go up and find a command that I want to use again, but with some ...
2
votes
1answer
67 views

Execute commands from history that match regex or grep

I was wondering if its possible to execute commands from history that match a certain regex? I know you can do something like fc 232 248 And it will go into your history and then do revisions ...
3
votes
1answer
205 views

Preserve tcsh history in multiple terminal windows

How can we preserve or maintain the same history across multiple terminals? The same question, but for bash shell , were discussed in the below link Preserve bash history in multiple terminal ...
0
votes
1answer
53 views

KSH on old unix systemV: search history

I have set a good ksh environement on old unix PATH=$PATH:/usr/lib/acct:/usr/sbin:/sbin:/usr/ucb export PATH EDITOR=vi FCEDIT=vi export EDITOR export FCEDIT HOSTNAME=`uname -n` HISTSIZE=500 ...