Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
91–100 of 114 posts
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#92Something 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.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#93Earlier quoted context omitted.
How many major versions of Perl do you know about? What is the distribution of these different versions of Perl across various OSes and OS versions? Hint: Lots of backward-incompatible changes tend to get made around different major versions. Having Perl 4 is not like having Perl 5 which is not like Perl 6.
I still don't know what your point is. Are there any contemporary distros that have the "perl" exectuable that is not Perl 5?
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#94Earlier quoted context omitted.
This is useful when saving command lines to files (scripts) using the POSIX-required fc builtin. Command line histories are relatively cumbersome to save with Ash, Bash saves them but truncates them to 500 entries, whereas scripts can easily be saved indefinitely. Amongst Bash and other feature-heavy shell users, there are Rube Goldberg-like workarounds for command line history saving. OTOH, all shells aiming for POS…
> Bash saves them but truncates them to 500 entries That behavior can be modified with the HISTSIZE environment variable. > The maximum number of commands to remember on the history list. If the value is 0, commands are not saved in the history list. Numeric values less than zero result in every command being saved on the history list (there is no limit). The shell sets the default value to 500 after reading any star…
echo "export PROMPT_COMMAND='history -a;history -r;export HISTFILE=-1;export HISTFILESIZE=-1;shopt -s histappend'" > .bashrc
cp .bashrc /etc/profileRe: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#95 sort file1 > file1_sorted
sort file2 > file2_sorted
diff file1_sorted file2_sorted
You can instead skip making two new files, and do: diff
And voila - you've got two 'files' you are comparing, but without having to save them to disk. The examples on the page use this with `curl` and `head` to good effect, but it wouldn't necessarily be obvious what's going on.Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#96Earlier quoted context omitted.
Plan9 sed has no -i option. Older versions of NetBSD will not have it either. I never understood the point of the -i option other than to conserve keystrokes. A temporary file is still created then removed; the -i option only saves the user from having to specify it. Maybe the intent is it is only for "one-off" use, not for use in scripts. This will work for GNU, BSD and Plan9: sed -n 's/old/new/wfile.tmp' file mv fi…
sed -i alone overwrites a soft or hard link with the contents of the file.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#97I 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`…
"And `cp -a`, which is like `cp -r` which leaves permissions intact - meaning you can prepend `sudo` without the hassle of changing ownership back." I always use pax instead of cp mkdir newdir cd olddir pax -rw -pp . ../newdir preserves permissions and access times cd olddir pax -rw -pe . ../newdir preserves ownership, permissions and access times.
bash: pax: command not found
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#98I 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`…
"And `cp -a`, which is like `cp -r` which leaves permissions intact - meaning you can prepend `sudo` without the hassle of changing ownership back." I always use pax instead of cp mkdir newdir cd olddir pax -rw -pp . ../newdir preserves permissions and access times cd olddir pax -rw -pe . ../newdir preserves ownership, permissions and access times.
Re: Bash-oneliner: A collection of handy Bash one-liners and terminal tricks
#99Earlier quoted context omitted.
"And `cp -a`, which is like `cp -r` which leaves permissions intact - meaning you can prepend `sudo` without the hassle of changing ownership back." I always use pax instead of cp mkdir newdir cd olddir pax -rw -pp . ../newdir preserves permissions and access times cd olddir pax -rw -pe . ../newdir preserves ownership, permissions and access times.
[fire@host ~]$ pax bash: pax: command not found
[-] pax-20201030_1 POSIX archiving utility pax from MirOS (plus tar and cpio)
https://ftp.debian.org/debian/pool/main/p/pax/Or try BSD.