|
How do I skip certain directories in "du" output?
On a mailing list I'm on, someone asked an interesting question about the du command: "I want to figure out how much disk space I'm using in different directories, but I don't know how to exclude certain directories from the output. Anyone have a suggestion?"
My initial response was that you'd want to just pour the output through a grep -v, or, if you want to get fancy and use a regular expression, grep -vE. Like this: It answered the question, but the intent of the person, however, was to also speed up the disk usage calculation itself; what he really wanted was to mask the directories within the du command. As he asked: "Would that skip retrieving the disk usage for any of those directories, or simply skip displaying the disk usage? The main problem with retrieving the information on those directories is that it can take a lot time." It doesn't skip getting the information, you're right. If you want to do that, then you need to explicitly list the directories you DO want to know about. One way to do that, though, is to drop a list of all directories in the current location into a file, then edit it to be what you want. Something like this: find . -mindepth 1 -maxdepth 1 -type d -print > .localdirsthen edit the results to match your needs. Whenever you want to run the du, use: $ du -s $(cat .localdirs)Or, if you're a backtick sort of person: $ du -s `cat .localdirs`I hope that helps you solve your problem!
Categorized:
Unix and Linux Help
(Article 3774,
Written by Dave Taylor)
Tagged: Previous: Does Lynx request images when viewing a Web site? Next: What's the best way to figure out if an eBay seller is legit? Subscribe!
Add a "-I foldername" (that's minus-capital-i) to the du command for each folder to skip:
Here are similar examples omitting a second directory: brighthold:~ % du -s admin/serverconfigs
-Dave Frank Posted by: David E. Frank at December 2, 2004 9:28 PMGreat data! Thanks for the update. Even better, the -I flag is a mask, so you can have a simple pattern (well, sequence of characters) that will mask more than one directory. However, that's a potential problem too, because -I admin would also block a folder called MyAdminTools and similar... Posted by: Dave Taylor at December 2, 2004 9:35 PMI have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |