Tagged Questions

recall commands previously typed in a shell or other utility

learn more… | top users | synonyms

2
votes
3answers
58 views

How to start first command from the list printed by command 'history | grep something'

For example, I have the following output from command: loom@loom:$ history | grep MAKE 219 ../build.sh -DCMAKE_BUILD_TYPE=Debug .. 909 history | grep MAKE How to write a command, that start ...
3
votes
1answer
234 views

Root complete history commands

Where can I get root's history except besides .sh_history? I've gotten some information but only from .sh_history and the history command.
2
votes
1answer
107 views

How to get a history entry to properly display on multiple lines

Suppose I have entered a function at the bash prompt, on multiple lines rather than squeezing it onto one with semicolons: $ function blah { echo blah } $ history -1 12690 function blah {\necho ...
2
votes
2answers
293 views

Bash's declare -p HISTIGNORE brings bash to a halt! Why?

Executing the following code in GNU bash, Version 4.2.45(1)-release (x86_64-redhat-linux-gnu), Fedora 19 ... shopt -s extglob export ...
0
votes
1answer
144 views

Where does bash store the time commands were executed?

Enabling history to display time via export HISTTIMEFORMAT='%F %T ' shows the times of the commands but .bash_history doesn't contain any times. Where does bash store the times the commands were ...
3
votes
1answer
116 views

Search Alt+F2 history

I wonder if there's some way to search the Alt+F2 "runner" history most preferably within the dialog itself. I know that in Cinnamon the values are available in dconf-editor under org.cinnamon ...
6
votes
2answers
500 views

Re-execute fc command from history

Sometimes I am using the fc builtin in bash (3.2 if that matters), to recall commands from the history. This also offers the possibility to edit, before execution. For example, by typing fc 23 27 ...
3
votes
3answers
325 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 ...
5
votes
2answers
315 views

Why does !! inside an alias not work?

I have this alias set in my system /etc/bashrc file: alias root="sudo !!" The intention of this being to run the last used command using sudo of course. When used, it of course appears to ...
4
votes
1answer
1k views

datetime stamp when running history command in zsh shell

When I run the history command on my ubuntu server, I get output as follows: history ... 25 cd ~ 26 ls -a 27 vim /etc/gitconfig 28 vim ~/.gitconfig I want to view the datetime ...
3
votes
2answers
110 views

Is it possible to transfer the history of commands from one system to another?

I am going to have all my data transferred to a new PC. Is it possible to transfer the command history of the previous Linux to the new system as well? So that when I type the history command, I get ...
3
votes
0answers
186 views

How to create a bash command which creates output that exactly mimics a source text file that can be pasted into bash shell where histexpand is on?

The goal is to create a bash one line command that can be copied and pasted - for instance published on a web forum - and then patches files. See it as a way to distribute a patch file by copy and ...
1
vote
1answer
939 views

Automatically save bash command history in screen session [duplicate]

I connect to a screen session. After doing some stuff I detach it. Then in history | tail I only see screen -r and previous commands and not the commands run in screen session. Basically history shows ...
0
votes
2answers
64 views

How to find by what means a software has been installed on linux

I have plenty of softwares installed on my Linux machine (RHEL) and some were installed with yum, some other by downloading a rpm and executed it from gnome file manager. I also have few softwares ...
1
vote
3answers
89 views

Terminal: Use different command on previous file

I know that there is the !! command to reuse the previous command. How would one reuse the file or directory specified in the previous command but use a different command on it? Example: I want to ...
2
votes
2answers
2k views

HISTTIMEFORMAT modification. In /etc/bash.rc or /etc/profile? [duplicate]

I'd like to add the date/time to the output of the history command in CentOS/RHEL 6. I would like this to apply to all users on the machine by default. This itself is easy. It seems to just be a case ...
3
votes
3answers
270 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 ...
12
votes
4answers
922 views

Search for a previous command with the same prefix when I press Up at a shell prompt

Coming from a FreeBSD world I wish to make the Linux terminal behave like FreeBSD one, especially the 9.1 version, basically when you type cd in the terminal and push the "up" arrow you can browse all ...
0
votes
2answers
94 views

Why must you be careful when using Bash's built in command history function to re-run previous commands that contain variables?

I know !! re-runs commands but what exactly would occur if I re-ran a command that had a variable in the command?
2
votes
1answer
207 views

Get the last executed command line in ksh

Is there a way to get the last executed command possibly together with the arguments within a ksh script? I am using mksh with cygwin. I tried fc -nl -1, but the script throws a "“fc: history ...
13
votes
2answers
363 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
96 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
202 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
120 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 ...
18
votes
1answer
780 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
99 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
1k 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
220 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
512 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 ...
9
votes
2answers
2k 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 ...
5
votes
1answer
1k 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?
17
votes
2answers
1k 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
50 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
332 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
174 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
350 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
150 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
138 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
48 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
100 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 ...
3
votes
4answers
572 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
246 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
31 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 ...
26
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
171 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
148 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
109 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
3answers
466 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
211 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 ...