Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
1–10 of 114 posts
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#2As a follow-up, I can also recommend Effective Shell series. I used to have navigation shortcut diagram from Part 1 (https://dwmkerr.com/effective-shell-part-1-navigating-the-co...) printed out.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#3If you’ve written a command but realize you don’t want to run it right now but want to save it in your history you can just put a `#` in front of it (ctrl-a #) making it a comment and allowing you to save it in your history without running it.
When you’re ready to run it you find it and remove the preceding `#`
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#4Learnt a neat trick from an old sysadmin colleague. If you’ve written a command but realize you don’t want to run it right now but want to save it in your history you can just put a `#` in front of it (ctrl-a #) making it a comment and allowing you to save it in your history without running it. When you’re ready to run it you find it and remove the preceding `#`
EDIT: This apparently needs to be configured - setting HISTCONTROL=ignorespace
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#5Learnt a neat trick from an old sysadmin colleague. If you’ve written a command but realize you don’t want to run it right now but want to save it in your history you can just put a `#` in front of it (ctrl-a #) making it a comment and allowing you to save it in your history without running it. When you’re ready to run it you find it and remove the preceding `#`
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#6Learnt a neat trick from an old sysadmin colleague. If you’ve written a command but realize you don’t want to run it right now but want to save it in your history you can just put a `#` in front of it (ctrl-a #) making it a comment and allowing you to save it in your history without running it. When you’re ready to run it you find it and remove the preceding `#`
The opposite is adding space before the command. The command will run but it will not be saved in history. EDIT: This apparently needs to be configured - setting HISTCONTROL=ignorespace
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#7That's a nice and very extensive collection. As a follow-up, I can also recommend Effective Shell series. I used to have navigation shortcut diagram from Part 1 ( https://dwmkerr.com/effective-shell-part-1-navigating-the-co... ) printed out.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#8I use Terminal.app’s Select Between Marks or tmux, but I wish this was a thing.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#9Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#10Something I’ve been wanting to do but haven’t found a perfect solution for yet: storing the output of previous command in some variable by default. I use Terminal.app’s Select Between Marks or tmux, but I wish this was a thing.
VAR=$(!!)
to accomplish something similar. Not by default of course.It re-runs the command, so if not idempotent/etc it will not return expected results. Also when re-run, the command will not be in a tty context, so if the executable is sensitive to such things (e.g. `ls`), the output format might be different.