You can then recall the cleared line with Ctrl+Y if you need.
You can then recall the cleared line with Ctrl+Y if you need.
You can then recall the cleared data using Ctrl+Y if you need.
You can then recall the cleared line with Ctrl+Y if you need.
You can then recall the cleared line with Ctrl+Y if you need.
Disadvantage: you can't recall the cleared line anymore.
Browse history with Arrow Up and Arrow Down
Browse through history with Ctrl+R, and by starting to type the command. If multiple commands with the same search pattern exist in history, press Ctrl+R again to loop through them.
Ctrl+O will run the selected command, and leave it in prompt
Typing the command history will display all history.
Also, you can grep the output like this: history | grep apt
Re-run a specific command from history referenced by command number: !#. !70 will rerun the command on position 70 in history file
Re-run the previous command !!. This is helpful when you forget to sudo, so you can use sudo !! to sudo the previous command, or you can use !! | grep text to grep the output of the previous command.
Run a recent command by referencing to part of it: !text. If you recently user the command ping 8.8.8.8, you can re-run it by typing !pi
Adding :p to the above outputs will print the command into terminal. !70:p, !!:p, !pi:p
Reuse the last argument from previous command !$. If you user ping 8.8.8.8, you can then traceroute it by typing traceroute !$. Note that this only uses the last argument, so after ping 8.8.8.8 -c 4 using it like traceroute !$ will result with traceroute 4.
Reuse the first argument from previous command !^, so after ping 8.8.8.8 -c 4, using traceroute !^ will result with traceroute 8.8.8.8.
Reuse all arguments from previous command with !*, so after ping 8.8.8.8 -c 4, using ping !* will result with ping 8.8.8.8 -c 4.
You can combine this with the command history: command !abc:# or command !abc:*
Correct the previous command with ^abc^xyz
su@www:~$ ping gogle.com ^C su@www:~$ ^gog^goog ping google.com PING google.com (216.58.214.238) 56(84) bytes of data. 64 bytes from bud02s24-in-f238.1e100.net (216.58.214.238): icmp_seq=1 ttl=115 time=10.9 ms 64 bytes from bud02s24-in-f238.1e100.net (216.58.214.238): icmp_seq=2 ttl=115 time=11.0 ms 64 bytes from bud02s24-in-f238.1e100.net (216.58.214.238): icmp_seq=3 ttl=115 time=11.1 ms ^C --- google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 10.917/11.020/11.105/0.077 ms su@www:~$
history -c will clear the history.
Configuring the HISTCONTROL variable allows to not store commands beginning with space, or duplicate commands - or both.
HISTCONTROL=ignorespace HISTCONTROL=ignoredups HISTCONTROL=ignoreboth