DirectNET

Data Center Management Solutions including UPS Systems, Data Center Cooling, KVM over IP & IP Power Strips, Server Racks and Server Rack accessories; KVM Switches and KVM Extenders; Rackmount Monitors and Rackmount Keyboards.


NAVIGATION
Home
Store
INSIDE MAC
Television Shows
Broadcast Shows
Daily News Shows
Special Shows
EVENTS
DAILY TIPS
Design
Mac OS X
Mac OS X UNIX
COMMUNITY
Forums
Surveys
NEWS
Current
Press
Archive
FEATURES
Editorial
Dr. Mac
Reviews
Reader Reports
RESOURCES
FAQ
Documentation
Learning Center
MAN pages
Glossary
Tutorials
Tips
Links

OUR PARTNERS

OSXFAQ Daily Unix Tricks   back to index

Week 49 - 'find' and 'xargs' (30 June 2003)

by Adrian Mayo - Senior Editor for Mac OS X Unix

Friday - Filenames With Spaces

If filenames have spaces, the 'find | xargs' combination will fail...

% ls -1
a file name.doc
b file name.doc

% find . -iname "*.doc" | xargs grep -il "Dear Sirs"
grep: ./a: No such file or directory
grep: file: No such file or directory
grep: name.doc: No such file or directory
grep: ./b: No such file or directory
grep: file: No such file or directory
grep: name.doc: No such file or directory

Use option '-print0' with 'find'. 'find' will print the pathname of the current file, followed by an ASCII NUL character (character code 0). Next, use option '-0' with 'xargs' so it will use NUL (``\0'') instead of whitespace as the argument separator.

% find . -iname "*.doc" -print0 | xargs -0 grep -il "Dear Sirs"
./a file name.doc

Discuss this trick in the Learning Center forum


If you want to learn more about Mac OS X Unix visit the Learning Center  click.

  • For beginners: the Mac OS X Unix Tutorial
  • For detailed information on specific topics: Mac OS X Advanced Unix
  • For answers to common problems: Mac OS X How To



Copyright © 2000-2009 Inside Mac Media, Inc. All rights reserved.
Apple assumes no responsibility with regard to the selection, performance, or use of the products or services. All understandings, agreements, or warranties, if any, take place directly between the vendors and prospective users.
Apple, the Apple logo, Mac, PowerMac G4, PowerMac G5, Xserve, Xserve RAID, PowerBook, iBook, Airport, AirPort Extreme, iMac, eMac, iLife, iMovie, iCal, iPhoto, iTunes, QuickTime, FireWire, iPod, iSight, AppleWorks, Macintosh, Jaguar, Panther, Mac OS, Mac OS X and Mac OS X Server are trademarks of Apple Computer, Inc.