6 Linux bash/zsh history shortcuts that will save you time (every Linux user should know this):
Using bash/zsh history effectively will save you a significant amount of time in the Linux terminal.
This will not only save you time, but it will also make your life much easier when using the LinuxtTerminal to perform day-to-day tasks as a regular user,developer or sysadmin.
This will not only save you time, but it will also make your life much easier when using the LinuxtTerminal to perform day-to-day tasks as a regular user,developer or sysadmin.
Here are 6 Linux bash/zsh history shortcuts that will save you time:
If you don't want your screen to be cluttered when viewing your history, you can limit the number of lines to display by using the history command with a numeric argument, where the value is the number of lines to display.
2. Searching commands from history:
There are two or more methods for searching through the bash history. Personally, I prefer to use the history command in conjunction with the grep command or a convenient shortcut to perform a reverse search through the history.
There are two or more methods for searching through the bash history. Personally, I prefer to use the history command in conjunction with the grep command or a convenient shortcut to perform a reverse search through the history.
- Using CTRL + R shortcut
A better and more convenient way to search through history is to use the CTRL + R shortcut key to initiate a reverse search and then type the string you're looking for.
A better and more convenient way to search through history is to use the CTRL + R shortcut key to initiate a reverse search and then type the string you're looking for.
You can cycle through the options by pressing CTRL + R repeatedly, and once you find the command you want, press CTRL + O or simply the 'enter' key to select and run it. Simply press ESC or CTRL + G to exit the reverse search.
3. Quickly executing commands from history:
Another useful feature of bash/zsh is the ability to run commands from the history using the ! command. That is, you can execute a command by typing !#, where # is the command's position/number in the history.
Another useful feature of bash/zsh is the ability to run commands from the history using the ! command. That is, you can execute a command by typing !#, where # is the command's position/number in the history.
This is very handy if you want to correct typos or mistakes on long commands.
5. Reuse arguments from previous commands in your history
Another fantastic history shortcut is to use!$ and!*, which will substitute/place the last argument and arguments of the last command into your line, respectively.
Another fantastic history shortcut is to use!$ and!*, which will substitute/place the last argument and arguments of the last command into your line, respectively.
6. Clearing your history
If you feel there are too many commands and you no longer want them, or if you don't want people or other users to know the commands you've been using throughout your session for security reasons, you can simply clear with the option '-c' or -d.
If you feel there are too many commands and you no longer want them, or if you don't want people or other users to know the commands you've been using throughout your session for security reasons, you can simply clear with the option '-c' or -d.
That's it! Thank you for making it this far. Hopefully, you'll find this thread useful. Any additions are welcome.
Check us out @linuxopsys if you liked this thread!! We gonna be tweeting more about Linux, sysadmin and devops.
Check us out @linuxopsys if you liked this thread!! We gonna be tweeting more about Linux, sysadmin and devops.
Loading suggestions...