Created
May 10, 2024 08:31
-
-
Save jdmichaud/2fce931fb2ab33ad17713da2b4f5152d to your computer and use it in GitHub Desktop.
Bash cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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