Live data from Hacker News

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

github.com

111–114 of 114 posts

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

#111

I was surprised to see `$()` missing from this (otherwise quite extensive) list. There are a few commands listed which employ it, but it absolutely deserves its own entry. That and `readlink -f` to get the absolute path of a file. (Doesn't work on MacOS; the only substitute I've found is to install `greadlink`.) And `cp -a`, which is like `cp -r`, but it leaves permissions intact - meaning that you can prepend `sudo`…

What does `$()`?

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

#112
A really nice list, thanks a lot for sharing! :)

I'd add this when a filesystem gets almost full (but not overfilled, see below). This shows where most of the space goes:

  # du -axm / | sort -n | tail # takes a while on large filesystems, or ones with lots of files
Then narrow down for each of the most filled directories:

  # du -axm /some/dir | sort -n | tail # subsequent searches are fast, now that metadata is cached.
In case there is no space at all, sort will complain if the /tmp directory is on the same fs, then the only option is to search any suspect directories with du -sm $dir

And about this one: https://github.com/onceupon/Bash-Oneliner#using-ctrl-keys

A bit surprised that the Ctrl+b(ack one...) and Ctrl+f(orward one char) shortcuts are not included.

As well as their Alt+b/f for a word back/forward too. Very convenient for going through a long command by getting in the beginning or the end of the line, then move words back/forth to update it.

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

#113

Ctrl + s : to stop output to terminal. Ctrl + q : to resume output to terminal after Ctrl + s. Who uses these? These are newb as well as advanced user killers that doesn't seem to serve a purpose. It just makes you think your shell is locked up making you think either the server is out of memory, process is hung to the point no keys would react or the network is hosed.

I /remember/ them from when I was logging in to "the computer lab" at my Uni from literally decades ago, but I haven't thought about them nor used them in at least that time.

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

#114

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.

might be kludgey but i wonder if bash coproc would help, it basically can send stdout to a named pipe that makes it avail as a environment variable fike descriptor.

That's interesting, but wouldn't work on an SSH session, I guess
Post reply on HN