Skip to content

Instantly share code, notes, and snippets.

@marclundgren
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marclundgren/fdbf3f4dddb4915031e7 to your computer and use it in GitHub Desktop.
Save marclundgren/fdbf3f4dddb4915031e7 to your computer and use it in GitHub Desktop.
xargs
# xargs takes a list of arguments and invokes the following command on each item in the list
# Demo: xargs
# Make some files with duplicates
➜ touch fileA
➜ touch fileA-duplicate
➜ touch fileB
➜ touch fileB-duplicate
➜ touch fileC
➜ touch fileC-duplicate
# Sanity: list all files
➜ ls
fileA
fileA-duplicate
fileB
fileB-duplicate
fileC
fileC-duplicate
# List all files that match a pattern. (e.g. files with the "duplicate" postfix
➜ ls | grep "-duplicate"
fileA-duplicate
fileB-duplicate
fileC-duplicate
# rm -rf is a destructive function that takes a file name
# Usage: rm -rf (aka trash) to a list of duplicate file names
➜ ls | grep "-duplicate" | xargs rm -rf
➜ ls
fileA
fileB
fileC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment