Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Created May 10, 2024 08:31
Show Gist options
  • Save jdmichaud/2fce931fb2ab33ad17713da2b4f5152d to your computer and use it in GitHub Desktop.
Save jdmichaud/2fce931fb2ab33ad17713da2b4f5152d to your computer and use it in GitHub Desktop.
Bash cheat sheet
# Mingle ls/xargs/extension substitution
ls somepath/*.txt | xargs -n1 -i bash -c 'echo cp "$1" "${1%.txt}.dat"' - '{}'
# - `-n1` will make xargs take only one parameter at a time instead of the whole list of files.
# - Using a bash command allows to pass {} (which is a xargs args) to the shell and perform substitution on it
# source:
# https://stackoverflow.com/a/965072/2603925
# https://stackoverflow.com/a/45895212/2603925
# https://stackoverflow.com/a/64924231/2603925
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment