
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!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Unix and Linux Help
(Article 3774)
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!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. 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 a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|