I love these one-liners. It's also about knowing your tools better. I hadn't known about `look` [0], which is great. The writer looks to be a bioinformatician, so it might be a bit out of scope, but I also found `socat` [1] quite a good serial communication helper tool. [0] https://man7.org/linux/man-pages/man1/look.1.html [1] https://linux.die.net/man/1/socat
Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
41–50 of 114 posts
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#42I 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's the use case for this sort of thing?
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#43sed -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…
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 sequences.Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#44I 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`…
>a copy of your original directory, with only the modified files actually taking up space What's the use case for this sort of thing?
What that has turned into is 'checkout the repo and make a new directory structure that symlinks everything back to the original'. The keeps the maintenance burden relatively small as you can easily update the base version, and only need to worry about the files you changed.
I certainly wouldn't recommend using this approach for anything; but it is not as terrible as it sounds.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#45Earlier quoted context omitted.
I don't recall where I heard it, but my understanding is that socat is the sort of successor to good ol' netcat. (Of course, don't ask me to compare each, nor know what socat brings that netcat lacks, etc.)
`socat` is netcat but for serial. [0] [0] https://serverfault.com/questions/246347/whats-the-differenc...
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#46I 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`…
>a copy of your original directory, with only the modified files actually taking up space What's the use case for this sort of thing?
If you `lndir` your mp3 directory to a functional copy of it, a playground of sorts, you can move things around and rename them without having to worry about scenarios like having to listen to a bunch of mp3s in order to put them back to where they're supposed to be.
When you're satisfied with the re-organization of your files, you can replace your symlinks with the original files. Since none of the directories are symlinked, you never have to worry about `cd`ing into a place you didn't intend to.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#47No, $SHELL is the user’s default shell; i.e. the shell started in a new terminal or when logging in on a console or remotely. If another shell program is started, $SHELL will still refer to the default shell, not the running shell program.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#48I 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`…
FWIW `realpath` on macOS should be functionally equivalent to `readlink -f` - particularly if you ignore all the other functionality `readlink` provides.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#49I love these one-liners. It's also about knowing your tools better. I hadn't known about `look` [0], which is great. The writer looks to be a bioinformatician, so it might be a bit out of scope, but I also found `socat` [1] quite a good serial communication helper tool. [0] https://man7.org/linux/man-pages/man1/look.1.html [1] https://linux.die.net/man/1/socat
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#50sed -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…
So, I'll stick to my printf thanks