Live data from Hacker News

Bash-oneliner: A collection of handy Bash one-liners and terminal tricks

github.com

1–10 of 114 posts

Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks

#3
Learnt 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

#4
post #3

Learnt 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

#5
post #3

Learnt 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 `#`

Lol that makes sense, never thought of commenting out the command but I guess I do something similar. If i realize i dont want a command yet I enter it with a trailing `\`, then `CTRL+C` to get back to an empty prompt.

Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks

#6
post #4
post #3

Learnt 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

Thanks to your comment, I learnt about ignoredups as well

Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks

#7
post #2

That'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.

Thanks for sharing, I love the animations and diagrams.

Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks

#8
Something 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.

Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks

#10

Something 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.

You can use:

  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.

Post reply on HN