|
|
Handy find | xargs Construct
The UNIX file command uses a "magic" set of data (/usr/share/file/magic) to identify file types. This is much smarter than expecting file extensions or Mac
file types to identify file content.
For instance, a JPEG may be named .JPG, .jpg or .jpeg or .JPEG.
Some examples: The following command will look for MP3 files:
The first argument to find, . (dot), is the starting directory. A similar bit for finding JPEGs:
The find FIND_EXPRESSIONS -print0 | xargs -0 COMMAND is a nice construct that can be used for other things besides file. Some examples:
will find all *.xls files below the fedl/ directory and zip them into fedfiles.zip.
will show the five largest files below fed/
Two key features with using the find -print0 | xargs -0 approach are that the command you specify will get multiple filenames per invocation and that it's "safe" with filenames containing special characters like spaces and quotes. Using a small example we can show that calling zip once with all filenames is faster than invoking it once per filename:
And also that an example of not using this technique which fails on filenames with spaces:
Many Unix commands support a null terminated list of filenames from find -print0 as input. While the syntax of xargs requires a bit of learning (RTFM) it is a very powerfull tool!
-m |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.05 seconds |
|