Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [command-history]

recall commands previously typed in a shell or other utility

1
vote
1answer
46 views

Is it possible to get the history of commands run with “at”?

I think the title says it. I would like to retrieve the history of commands run a few days ago with at to double check some error we got on an import process.
2
votes
3answers
178 views
+50

Alternative to Ctrl-R reverse search in bash

I am happy and really like the Ctrl-R backward search feature of the bash shell. Some of my colleagues don't like it, since it is sometimes confusing. I understand them. If you enter the wrong ...
1
vote
3answers
34 views

“su doesn’t record the commands executed as root”

I am currently reading book Unix and Linux system administration - Evi Nemeth. On page 70 under the topic "su: substitute user identity" there is a statement that says "su doesn’t record the commands ...
6
votes
5answers
618 views

When is a multiline history entry (aka lithist) in bash possible?

In the bash reference manual it states: lithist If enabled, and the cmdhist option is enabled, multi-line commands are saved to the history with embedded newlines rather than using semicolon ...
51
votes
10answers
44k views

How can I search history with text 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 ...
5
votes
2answers
343 views

How to protect against purge of bash history?

Following the answer: When closing multiple bash instances at the same time, there is a known race condition that may cause the history to be cleared. This occurs because there is no locking ...
3
votes
1answer
71 views

Logging Shell Activity

Is there a way to produce a custom activity log in my BASH shell? It would save, in each row, the last command, the time when it was run, and the working directory from which it was run. Note: It ...
1
vote
1answer
59 views

Is there a way to save all bash commands from all terminals to a single file? [duplicate]

Is there a way to save all bash commands from all terminals to a single file? By default, different terminals have different history and that gets confusing. I'd like to save all history to a single ...
0
votes
2answers
40 views

Create a wrapper around bash using a bash function

I am kinda wary of messing with bash history settings and I just want to write my own custom bash history. I thought about using a bash function like this: bash(){ # write to a custom history file ...
-1
votes
1answer
57 views

Use PROMPT_COMMAND to echo to custom bash history file [duplicate]

I executed the command below in a BASH shell. export PROMPT_COMMAND='echo "$BASH_COMMAND" >> $HOME/my_bash_history' but everytime I type something in the shell and hit return, I just get one ...
511
votes
20answers
170k 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 ...
1
vote
1answer
14 views

Setting up aliases for a history expansion pattern

similar to the existing $_ which I learned stands for !-1:$, I would like to create aliases for $__, $___ and so on which refer to the 2nd or 3rd -last command. I have tried adding alias "$__"='!-2:$'...
0
votes
1answer
27 views

Expand alias in ZSH history

I have the following alias in my zshrc alias nif='nvim $(rg --files | fzf -m || echo +qa)' Essentially, I use rg (ripgrep) to show all the files in the current directory and in sub directories. This ...
3
votes
0answers
134 views

how to avoid writing failed bash commands to bash_history

I'm looking for a nuanced history behavior I haven't seen anywhere. During a terminal session, I want every command, regardless of exit status, to be appended to the in-memory history. Upon exiting ...
35
votes
4answers
22k 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 close ...
1
vote
2answers
1k views

How do I know from which IP address a command was executed in SLES 11

I'm new to SLES and I need to know what IP address executed a command. I've searched and all I came across this but I do not have /var/log/auth.log or /var/log/secure. I don't know if it has to be SSH ...
1
vote
0answers
38 views

Is it possible to write “time” to bash history? [duplicate]

I love to know how long my CLI commands take so I often preceded them with time - sometimes I forget. Also I don't keep a record of long running commands so can't see if they vary over time. My bash ...
5
votes
2answers
7k 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 ...
2
votes
0answers
46 views

history is shifted by 5 lines

In .bashrc I have: HISTSIZE=5000 HISTFILESIZE=10000 wc -l .bash_history gives 10000 as expected, so when executing history immediately after opening the terminal, 5000 lines are printed. However, ...
1
vote
3answers
97 views

Shell command to put recent line of output onto current command line

Shells have a useful feature where pressing the keyboard UP arrow replaces the contents of the current command line with the previous command that was entered. (And if you do it again, the command ...
59
votes
11answers
67k views

How do I clear the Gnome terminal history?

When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?
10
votes
3answers
944 views

Remember “local” bash history in a folder?

I have a script in a folder that I use with long arguments. Is there any chance I can have an history of the commands executed in that specific directory instead of going back through the entire ...
101
votes
5answers
116k 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 worked -...
25
votes
9answers
3k 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 ...
6
votes
2answers
2k views

How to get the IP of a user who executed a command?

I figured out the timestamp of a specific rm -r command run on an Ubuntu machine from history. Now, I want to get the IP of the user who executed this command. Is there any way I can do this?
0
votes
1answer
29 views

Short command or alias to copy last command to clipboard

Often I'd like the command I just typed to put into the clipboard, and I'd like to do it from the command line. I came up with: alias cl="fc -ln -1 | sed 's/^\s*//' | xsel -b" To alias cl to that ...
92
votes
3answers
19k 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" ...
59
votes
3answers
3k views

With BASH after “scrolling” up to a previous command… how to then move on to the next in this history?

When I say "scrolling" up, I mean using the "up arrow" key on the keyboard, which obviously scrolls you up through the history, starting at the most recent command. So you find a command maybe 30 ...
7
votes
3answers
3k 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 ...
3
votes
3answers
2k views

Create history log per working directory in bash

I was wondering if it is possible to keep a file containing history per current working directory. So for example if I was working in /user/temp/1/ and typed a few commands, these commands would be ...
19
votes
7answers
22k views

History command inside bash script

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 using BASH script ? Here we go my script for you: #!/bin/bash history | tail -100 ...
1
vote
1answer
178 views

history -a not working in bash

Am I doing something wrong? I think I'm following the directions in the man page, and it's just not having any effect. [501] $ history | tail 492 echo 3 493 echo 4 494 echo 5 495 echo 6 ...
55
votes
7answers
22k 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 ...
0
votes
0answers
32 views

Seek local shell history, or ways to move .bash_history off site (ssh)?

There is no doubt that a shell history feature a la .bash_history makes it simple to keep keep track of stuff. However I do not wish to clutter an ssh account needlessly leaving a history of my ...
53
votes
7answers
17k 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 ...
6
votes
2answers
987 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 ...
0
votes
0answers
34 views

show history of curl requests including executing user or program?

Little Snitch just told me that curl made a silent connection to tools.google.com. I'd like to know why. is there a way to get the history of commands on my system including who executed them?
101
votes
6answers
57k 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
2answers
211 views

How can I permanently correct a typo in my last bash command?

It's not uncommon that I make a typo when entering commands in my bash interactive shell. I'd like to be able to correct the typo in my bash history so that the incorrect command does not pollute it ...
0
votes
0answers
55 views

Accessing command history in dash

When I try to run history in dash, I get an error message. This is expected as far as I can tell. When I run fc I too get an error message like "dash fc: not found". So how do I access the command ...
3
votes
2answers
88 views

Persistent command history?

Is there a way to persist the command history and search it or group it by command? In other words, I would like to list, say every grep command I have done over the last 3 months. Is that capability ...
5
votes
2answers
183 views

Add BASHPID to history?

I often have multiple sessions running at any given time. This sometimes leads to issues when trying to reconstruct work using history. As a result, I was thinking it would be useful to include the $...
3
votes
1answer
2k views

Sending bash history to syslog

Bash version 4.N has apparently the ability to write command-history to syslog, but I can't find information about how to configure this. I have read several pages which offer hacks using the ...
5
votes
1answer
277 views

Why does “less” sometimes forget its history

I set and exported $LESSHISTFILE and $LESSHISTSIZE but if I perform a search in one less session, close, reopen it and try to repeat my last search I get "No previous regular expression (press RETURN)...
33
votes
4answers
51k 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 ...
0
votes
1answer
18 views

Bash's history behavior when using ! and ! :p for old commands changed

Suddenly my bash history behavior changed. When I'm either calling an old command using !num (where num is the number of the commmand as seen in history) or displaying the command (without running it) ...
2
votes
1answer
56 views

History expansion in scripts [duplicate]

I have the following Bash script case $- in (*H*) echo enabled ;; (*) echo disabled ;; esac set -H case $- in (*H*) echo enabled ;; (*) echo disabled ;; esac pwd last_command="!!" echo $last_command ...
0
votes
0answers
70 views

Difference between zsh-history-substring-search and up-line-or-beginning-search

Is there a practical difference between history-substring-search-up and up-line-or-beginning-search? I've tried both out and they effectively seem to do the same thing (besides some highlighting that ...
2
votes
1answer
502 views

zle reset-prompt prevents browsing history with arrow keys

I just installed zsh and oh-my-zsh (my previous shell was bash). My .zshrc is completely unmodified from oh-my-zsh's default settings. The "git" plugin is the only enabled plugin (it's enabled by ...
8
votes
3answers
3k views

How to have command history with timestamps output to the terminal continuously?

I use a simple alias to enable the "tracking" of commands in one or many terminal window(s): alias trackmi='export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"' Then I just tail -f my .bash_history ...