Created
June 5, 2013 13:01
-
-
Save paulboardman/5713687 to your computer and use it in GitHub Desktop.
Example of a find command that doesn't work as expected. The 'ls' command is only executed on the *.tsv files due to the way the expression is evaluated: from left to right with the implicit '-and' between the second '-name' and '-exec' exec having higher precedence than the '-or' between the two '-name' tests..
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
find . -name "*.csv" -or -name "*.tsv" -exec ls -lh {} \; | |
# this is actually executed as: | |
find . -name "*.csv" -or \( -name "*.tsv" -exec ls -lh {} \; \) | |
# when what you wanted was: | |
find . \( -name "*.csv" -or -name "*.tsv" \) -exec ls -lh {} \; | |
# the general recommendation is to use xargs inplace of the -exec action | |
find . -name "*.csv" -or -name "*.tsv" | xargs ls -lh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment