Last active
August 29, 2015 14:22
-
-
Save marclundgren/fdbf3f4dddb4915031e7 to your computer and use it in GitHub Desktop.
xargs
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
# 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