recall commands previously typed in a shell or other utility

learn more… | top users | synonyms

14
votes
2answers
335 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 ...
3
votes
2answers
86 views

How to show last command with expanding function in bash

I'm using function like this. $ find-grep () { find . -type f -name "$1" -print0 | xargs -0 grep "$2" ; } After I type: $ find-grep *.c foo I want to get expanded last command string. In this ...
3
votes
1answer
147 views

What could cause my bash history to be cleared unexpectedly?

Today I noticed that my bash history is cleared completely. I have neither executed history -c nor deleted the .bash_history file. Apart from deleting the .bash_history file and history -c, how can ...
2
votes
0answers
87 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 ...
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?
4
votes
2answers
95 views

Why do I see different versions of bash history for the same user

I ssh into my servers using root. Sometimes when I scroll back in my history, I see a history from an earlier session, but not the last session. Why does this happen with the same user account? Is ...
0
votes
1answer
764 views

HISTTIMEFORMAT does not show correct date and time for history

After exporting HISTTIMEFORMAT='%F %T' I tried to query history But the result shows all the commands are executed on same day. How can I check the actual date and time of actual command execution?
1
vote
2answers
207 views

shell saves ip address that you ping? [duplicate]

I was once shown a shortcut that I can't recall/ find. After pinging an ip, then attempting to ssh into it - the ip was saved into to a variable automagically. Something like: ping 10.1.23.4 ...
14
votes
5answers
482 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 ...
8
votes
2answers
684 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 ...
4
votes
1answer
852 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?
14
votes
1answer
656 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 ...
1
vote
2answers
47 views

Can I see in history output from which directory I had actually issued a command?

CTRL+R allows me to reverse search through the command history which is great but can I also find out from which directory that command was run? I am using C-shell in Linux.
4
votes
3answers
201 views

Tricks for avoiding bash history logging? [duplicate]

What are some tricks for avoiding bash history being logged in a fascist logging environment that does not involve modifying .bash_rc or deleting content from within the history file?
2
votes
6answers
163 views

Bash - Split the previous commands parameters

How would one parse the previous command in bash? Example: root$ ssh foo@1.2.3.4 root$ echo !$ &>/tmp/foo.txt root$ cat /tmp/foo.txt foo@1.2.3.4 Goal: Send just the ipaddress 1.2.3.4 to ...
0
votes
2answers
241 views

How to use the last command in the while loop?

I am wondering how to modify this code. ls while [ 1 > 0 ] do fc -s sleep 1 done For fc -s, you can refer to this question for details. My question are as follows: How will it run? If you ...
4
votes
1answer
129 views

Diff the output of the last two commands

I frequently find myself doing something like the following: $ big long command 1 $ big long command 2 $ diff -u <(big long command 1) <(big long command 2) How can I get the shell (bash in ...
5
votes
1answer
137 views

Why does `!45` get replaced with `top`?

I was trying to a string search within Ubuntu 12.04 which went as follows: find . -exec grep -l "!45" {} \; Instead of searching for the string "!45", it was replaced with top. It didn't invoke the ...
3
votes
1answer
46 views

How to revert direction for last parameter shortcut?

I can append a last used parameter via the keyboard shortcut Alt + . yet sometimes, I type too fast and miss my actual target. If I wanted to go back one instance, is there a way to do it? I ...
4
votes
1answer
94 views

History of commands and directories we were in

I was wondering: If I type history I can see the previous commands I typed and see what happened and perhaps keep commands as reference. But I don't know in which directory I was when I typed the ...
2
votes
3answers
372 views

Shell: How do I get the last argument the previous command when it was detached?

Within the shell, typing ALT+. or using !$ recalls the last passed argument of the previous command. I use this all the time, but how do you do that when you detached the previous command? $ ...
4
votes
3answers
188 views

Use bash history file from old machine when setting up new machine?

I love my bash history. Sometimes I've issued really long commands and I really depend on my bash history to get them back quickly. I've increased my history size with: HISTSIZE=100000 ...
1
vote
0answers
30 views

why bash history overlap the prompt when scroll up in the history? [duplicate]

I customized my bash prompt, PS1 value. ~/.bashrc: Color_Off='\e[0m' # Text Reset BGreen='\e[1;32m' # Green BPurple='\e[1;35m' # Purple BWhite='\e[1;37m' # White ...
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).
4
votes
4answers
168 views

echoing symbols in terminal/bash

Why am I not able to use "!" when trying to echo a message in terminal? For example: echo -e "Hello\nWorld!" bash returns the following command: bash !: event not found
3
votes
3answers
143 views

Persistent shell arguments

I often find myself running a series of commands on a single set of arguments. For example: $ nmap -Pn -sS 192.168.1.5 $ ssh 192.168.1.5 $ curl 192.168.1.5 $ wget -r 192.168.1.5 This can be sped ...
1
vote
0answers
97 views

Zsh: quickly bookmark commands

I just had an idea, I'm sure it must exist though I could not find anything on the web. This topic gets close to my idea but not enough: How to quickly store and access often used commands? I'd like ...
1
vote
2answers
304 views

Different “history” command output after reconnecting via SSH

Why do I get different results for the "history" command for the same user after I reconnect a disconnected SSH session? I connect to a server using putty (SSH), say as root My network gets ...
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. ...
3
votes
3answers
192 views

Lots of text files into one big text file

I want to combine thousands of little text files into one big text file. I have them in directories with the structure: timestamp1/status.txt. For example: 20130430133144/status.txt. So far, I know ...
4
votes
1answer
215 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 ...
3
votes
1answer
92 views

Keep two bash history files, one with ignoredups, one with everything

For the purposes of looking at which commands I am using the most, I'd like to keep a record of command I type in my bash history (even duplicates). But, for sanity and ease of use, I still want to ...
4
votes
2answers
158 views

Bash Command (History) Number In PS1

I am a noob in bash to be honest. I have Googled around and cannot find an answer to this: history lists previous commands and their number e.g. $ history 286 clear I want to be able to see the ...
1
vote
3answers
275 views

Best tool for monitoring server usage

I was just wondering what the best tools for retracing logs and what logs I should be checking to work out what's going wrong with a server, or what the client has executed to get the server into it's ...
1
vote
1answer
146 views

Enable previous command cycling at ftp prompt

Currently on pressing arrow keys or Ctrl+P/N, I see characters like ftp> ^[[A ftp> ^[[B ftp> ^P ftp> ^N I would like to know, how to configure the ftp prompt so that I am able to view ...
9
votes
1answer
5k 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 ...
-2
votes
2answers
897 views

History command in ksh not able to use [closed]

I am using the ksh shell. I am not getting any impact of these following commands. It is executing without any error but it is not giving the proper results. export HISTTIMEFORMAT='%F %T ' Use the ...
3
votes
1answer
50 views

How can I prevent edited commands from overwriting the original? Or revert edits?

Often I'll execute a command in bash, press the up arrow to retrieve it from history, edit it, and execute the edit. However, sometimes I'll decide to discard the edit and run a different command or ...
4
votes
3answers
133 views

Can any shell do argument-level interactive search?

Sometimes I need to reuse certain long arguments like paths. If I use history search (CTRL+R), I may find some command that contains the path, but I still need to delete anything else in the old ...
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 ...
3
votes
1answer
724 views

Keep all commands in bash history?

I have the opposite question to this. How do I keep all commands in bash history? In Ubuntu since quite some time now, the default for bash is to forget commands with non success exit code. This is ...
1
vote
3answers
2k views

How to run the most recent command on AIX?

How can I run the most recent command again from history in AIX Server? And how to edit the most recent command and run it again in AIX?
1
vote
2answers
1k views

Shell - Deal with multiple command history files

Where I work, for security and auditing purpose, we have to keep one history file for each session (user, date, terminal, etc in the file name). Obviously, the HISTFILE variable, is set to read only ...
9
votes
2answers
828 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?
6
votes
1answer
408 views

Why does this PS1 value cause unexpected behaviour? [duplicate]

Possible Duplicate: Why is my bash prompt getting bugged when I browse the history? I have set my PS1 variable in .bashrc to be the following: PS1='\e[35m[\W]:\e[0m ' It achieved what it ...
9
votes
1answer
824 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 ...
7
votes
1answer
1k views

Bash history with timestamps

I would like to keep timestamps on the commands logged in my Bash $HISTFILE, is it possible? I did not manage to set it up using man bash as an information source. My other options are as follows: ...
16
votes
1answer
9k 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?
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
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 ...