Skip to content

Instantly share code, notes, and snippets.

@metaquanta
Last active November 25, 2020 07:52
Show Gist options
  • Save metaquanta/2165b83627f95e0bc35f986227845c5e to your computer and use it in GitHub Desktop.
Save metaquanta/2165b83627f95e0bc35f986227845c5e to your computer and use it in GitHub Desktop.
Shell foo
# for each line of cmd1, pass it to cmd2.
# cmd1 | each cmd2 %
alias each="xargs -I% -d '\\n'"
# print the sizes of dirs(!) and files in cwd.
alias lsz="du -d 1 -h"
# this'll format /proc/xxx/cmdline as expected.
alias strs='strings -s \ -1'
# like `open` on a mac
alias open=xdg-open
# deb stuff to remember.
alias apt-hold='apt-mark hold'
alias apt-requested='apt-mark showmanual'
~~~~
xargs -I_ -d '\n'
~~~~
`-I_`: replace '`_`' with the argument in the command
`-d '\n'`: treat the input as specifying an argument per line
~~~~
find . -name Makefile | \
xargs -I_ -d '\n' grep -H gcc _
~~~~
search all the `Makefile`s for `gcc`. (`grep`'s `-H` makes grep print the filename for each match. It wouldn't by default when given a single file to search)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment