Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
61–70 of 114 posts
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#62Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#63Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#64Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#65Earlier quoted context omitted.
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.
Yeah, I know, but I don’t want to re-run and I want it by default.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#66Earlier quoted context omitted.
When I need to shuffle around and/or rename my media files, for instance, it's risky to operate on the originals themselves. I've screwed up hundreds of mp3 files by issuing a bad `rename` command. I've lost the hierarchical structures of genres and artists and albums and such by accidentally moving them into the same directory together. And so on. If you `lndir` your mp3 directory to a functional copy of it, a playg…
You could use hardlinks for this, though (as long as both places are in the same filesystem). Then when you're finishes you just delete the old folder.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#67> Ctrl + x + Ctrl + e : launch editor defined by $EDITOR to input your command. Useful for multi-line commands. -- Great, I was just trying to remember that key combination the other day. Just got back to work after being for awhile for a child bonding leave.
Is that Ctrl+x, Ctrl+e? Or Ctrl+x+e? Or both controls?
- C-x, C-e (separately)
- C-(x,e) (hold ctrl, x and e separately)
- C-(x+e) (hold ctrl-x and press e)Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#68sed -i Watch out, that's a Linux-ism and macOS's sed will cheerfully use the thing after it as the backup expression; as far as I know, the absolute safest choice is to always specify a backup extension "sed -i~" or "sed -i.bak" to make it portable, although there are plenty of work-arounds trying to detect which is which and "${SED_I} -e whatever" type silliness My contribution (and yeah, I know, PR it ...) is that…
Using raw escape codes is ugly and device-dependent. People learned this in the 1970’s, and created libraries to get away from having to hard-code escape codes. Here’s a device-independent variant: title(){ tput tsl || tput -T xterm+sl tsl; printf %s "$*"; tput fsl || tput -T xterm+sl fsl; } Note: if the terminal does not advertise support of the necessary capabilities, it falls back to using the XTerm escape sequenc…
+ printf %s 'hello world'^M^Jhello world+ tput fsl^M^J+tput -T xterm
and that's where it cuts off but I presume ends with "^M^J" at the end :-DRe: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#69Earlier quoted context omitted.
I had been in the habit of symlinking ~/.bash_history to /dev/null to avoid AFS/NFS writes on every local command execution. When I moved over to the financial industry, it didn't occur to me that such a symlink might look like an attempt to evade monitoring. A year or two in, I realized it didn't look good, but it had clearly been made my first week on the job, so I just left it in place for over 10 years rather tha…
> I hope and presume they had much better monitoring than scanning bash history, but I'm not bet-my-career confident of that. bash has an "audit" function which is normally compiled out. https://git.savannah.gnu.org/cgit/bash.git/tree/configure#n1... When enabled it logs to syslog.
Instead, the Kernel has built in functionality called Auditd[0], which is capable of logging any and all executions, file or socket accesses, and much more. Along with included tooling for quickly finding and alerting on events[3].
Further, if terminal logging or playback is really required (usually not), it's generally done through pam with tlog[1]. Red Hat 8 and above come with built-in tlog support[2].
[0] https://access.redhat.com/documentation/en-us/red_hat_enterp...
[1] https://github.com/Scribery/tlog/blob/main/README.md
[2] https://access.redhat.com/documentation/en-us/red_hat_enterp...
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#70Something 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.