home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 15.5 Matching All "Dot Files" with Wildcards Chapter 15
Wildcards
Next: 15.7 Getting a List of Matching Files with grep -l
 

15.6 Maybe You Shouldn't Use Wildcards in Pathnames

Suppose you're giving a command like the one below (not necessarily rm -this applies to any UNIX command):

% 

rm /somedir/otherdir/*

Let's say that matches 100 files. The rm command gets 100 complete pathnames from the shell: /somedir/otherdir/afile , /somedir/otherdir/bfile , and so on. For each of these files, the UNIX kernel has to start at the root directory, then search the somedir and otherdir directories before it finds the file to remove.

That can make a significant difference, especially if your disk is already busy. It's better to cd to the directory first and run the rm from there. You can do it in a subshell (with parentheses) ( 13.7 ) if you want to, so you won't have to cd back to where you started:

% 

(cd /somedir/otherdir; rm *)

There's one more benefit to this second way: you're not as likely to get the error Arguments too long . (Another way to handle long command lines is with the xargs ( 9.21 ) command.)

- JP


Previous: 15.5 Matching All "Dot Files" with Wildcards UNIX Power Tools Next: 15.7 Getting a List of Matching Files with grep -l
15.5 Matching All "Dot Files" with Wildcards Book Index 15.7 Getting a List of Matching Files with grep -l

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System