All Questions
19 questions
0
votes
2
answers
716
views
How to remove any commands that begins with "echo" from history
I have tried the following:
history -d $(history | grep "echo.*" |awk '{print $1}')
But it is not deleting all the commands from the history with echo
I want to delete any commands which ...
2
votes
3
answers
449
views
how to run history -a command at regular intervals automatically?
I am using bash shell and I execute history -a command once in a while manually. My typical shell session lasts for weeks if not for months and I rarely exit my shell session. Thus, I force writing my ...
2
votes
1
answer
999
views
In bash, how do I run the last command that contains a string?
I'm using a bash shell. Normally if I want to repeat the last command that begins with a certain string, I can run
$ !cat
What if I want to run the last command that contains a string? That is, if ...
1
vote
0
answers
108
views
Selectively delete bash history using a script when the shell is closed
I can delete history using something like this:
history -d 2038
Or use in combination with grep.
What I want is to clean the history selectively when I closed the shell:
to delete often use commands,...
0
votes
1
answer
246
views
!! bash command
When we run !! in a shell session, it prints and run last executed command
I was wonder if it is an alias for another long-written bash built-in command and would like to know where it is defined
I ...
4
votes
1
answer
822
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
...
1
vote
1
answer
325
views
How to set an alias upon command execution?
I want other developers to have some convenient methods. Therefore I want to give them a script, that automatically sets an alias.
E.g the command grunt compileModule:[modulename] should set the ...
18
votes
1
answer
5k
views
Is history expansion disabled in scripts?
I understand the following error is due to ! used for history expansion:
$ echo "Hello!Tim"
bash: !Tim: event not found
However if I put the command into a script and run the script, there is no ...
1
vote
2
answers
221
views
Execute bash script so that each command is individually accessible in the shell's command history
How can I execute a bash script in such a way that each of the commands in the bash script can be selected using
the up arrow after execution?
Example script:
#!/bin/bash
command #1
command #2
...
1
vote
1
answer
212
views
Save temporary history via script
I want to save the temporary history to a file via script. In the bash it works like that:
history -a /tmp/tmp_history
But if I add this line to my script, the tmp_history is empty. I use it like ...
36
votes
1
answer
2k
views
How does !! work in bash?
Very useful when you forget a sudo at the beginning of your command, !! acts like an alias of the previous command. Example :
$ mv /very/long/path/for/a/protected/sensible/file/caution.h .
(...) ...
3
votes
3
answers
4k
views
Grab the last executed command from history as a string and store in variable in bash
I'm trying to grab the last executed command, with options, and store it as a string to be written to a file. I've tried using fc but that can only give me the next to last command (for me anyways) ...
3
votes
2
answers
7k
views
Write bash_history to a file with a timestamp
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 with date and time but it also ...
0
votes
1
answer
197
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 (...
0
votes
1
answer
76
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 ...