# 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
➜