Skip to main content

All Questions

0 votes
1 answer
380 views

Command line / prompt is broken, cannot edit (WSL2)

I'm using Windows 10 with WSL2. In all the terminals I have tried so far, I quickly encounter a broken command line. After pressing ENTER, the actual command appears differently, parts of the command ...
Alexander Nenashev's user avatar
0 votes
0 answers
112 views

duplicated history entries at the same timestamp

For some time I had an issue with my history using GNU bash (version 4 and 5) where commands appeared in duplicates. I assumed this was due to the fact that in my .bashrc I had the following line: ...
n0542344's user avatar
  • 406
1 vote
2 answers
296 views

View History Expansion On History

I am having to to rewrite history expansion commands, instead of calling it from history. For Example, I have to change 35 to 36, 37, 38.... in the following command. $ print -P '\033[35mThis is the ...
Ahmad Ismail's user avatar
  • 2,978
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 ...
artu-hnrq's user avatar
  • 327
11 votes
8 answers
2k views

How to Quickly Replace a Parameter in a Piped Command Chain

Question Let's say I just entered this command to get a count of how many lines contain a particular string: me@machine $ command-producing-multi-line-output | grep -i "needle" | wc -l Now how could ...
Jeff Reeves's user avatar
1 vote
1 answer
1k views

Bash prompt getting garbled when I browse history?

I have MacOS and .bash_profile content: export PS1="\[\e[0;31m$\]\[\e[m\] \[\e[0;32m\w\e[m\] : \]" as a result I have pwd printed in terminal like this: but when I press up and down arrows to use ...
Vladimir Gerasimenko's user avatar
3 votes
2 answers
2k views

How to import bash history with correct time&date from a history output?

I have a file with my bash history and want to "import" the commands on a new machine. The file contains a history output formatted as HISTTIMEFORMAT="%F%t%T%t": $ history > history.txt So the ...
automatix's user avatar
  • 217
1 vote
0 answers
722 views

Bash stdout and/or stderr history log [duplicate]

As you probably know, the bash shell's stdin is logged to $HISTFILE (i.e. usually ~/.history) and can be accessed with the history builtin, and so on. But the stdout & stderr are not. How can ...
voices's user avatar
  • 1,312
20 votes
2 answers
1k views

Does a shortcut for executing a series of commands in bash history exist?

Suppose I have the following trivial example in my history: ... 76 cd ~ 77 ./generator.sh out.file 78 cp out.file ~/out/ 79 ./out/cleaner.sh . 80 ls -alnh /out ... If I wanted to execute commands 77, ...
MrDuk's user avatar
  • 1,657
9 votes
6 answers
7k views

Repeat last command N times

Short of writing a loop, is there a way to repeat the last command N times. For example, I can repeat the last command once by using a double bang (!!), but how do I repeat it say 30 times?
Tyler Durden's user avatar
  • 6,105
1 vote
2 answers
97 views

Is it better to use !! or history?

I've found out the useful shortcut !! which can be used when you forget sudo before the command. You'll easily type $ sudo !! I've been doing this another way for a long time with up arrow, ctrl + ...
xralf's user avatar
  • 15k
20 votes
6 answers
1k views

How do I input n repetitions of a digit in bash, interactively

I'd like to run the command foo --bar=baz <16 zeroes> How do I type the 16 zeroes efficiently*? If I hold Alt and press 1 6 0 it will repeat the next thing 160 times, which is not what I want. ...
Jonas Kölker's user avatar
2 votes
1 answer
660 views

Clear bash history except last n lines

I have following command to clear last entry of bash history(terminal history/command-line history). My Ubuntu 14.04 Trusty Tahr. sed -i '$d' ~/.bash_history But I want to keep last 1,2...n entries ...
Vicky Dev's user avatar
  • 259
2 votes
2 answers
9k views

How do I record all terminal input and output to a local file by default for each session?

I'm aware the script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my ...
user208145's user avatar
  • 2,585
2 votes
2 answers
257 views

Is there a shortcut to rerun a command with arguments from last command (not cd, ls or echo)

Searching through passed Logfile with something like this: cat /path/to/logfile | grep -iEw 'some-ip-address-here|correspondig-mac-adress-here' This gives me all the passed log lines until now so I ...
konqui's user avatar
  • 165

15 30 50 per page