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`…
Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
111–114 of 114 posts
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#112I'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 $dirAnd 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
#113Ctrl + 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.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#114Something 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.