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


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 24.14 Don't Use strip Carelessly Chapter 24
Other Ways to Get Disk Space
Next: 24.16 Trimming a Huge Directory
 

24.15 Trimming a Directory

In article 4.7 , we mentioned that it's good to keep directories relatively small. Large directories can make your system seem slower because it takes more time to look up files. How small is "small"? Under 60 files is great.

However, there's a problem: the size of a directory can only increase. That is, creating new files can make a directory bigger; deleting new files doesn't, in itself, make the directory any smaller. I'm not saying that a directory grows every time you create a new file. That's not true; if you've deleted a file, the directory will have an empty entry in it, and UNIX can re-use the empty entry. But the fact remains: a directory can only get bigger; it can never get smaller, unless you delete it. [Some BSD systems will "squeeze" directories smaller. -JP  ]

So let's say you've been sloppy and have a few directories around with hundreds of files, a lot of which is junk you don't need (I've been there). You could just delete the junk, which would make your disk happier, but you haven't reduced the directory's size. What do you do? Here's a trick:

  1. Rename the old directory:

    % mv project project.toobig
    
    

  2. Create a new directory with the old directory's name:

    % mkdir project
    
    

  3. Move only the files you want from the old directory into the new directory:

    % mv project.toobig/*.txt project
    
    

  4. Now the old directory contains only junk. Delete the old obese directory and everything in it:

    % rm -r project.toobig
    
    

- ML


Previous: 24.14 Don't Use strip Carelessly UNIX Power Tools Next: 24.16 Trimming a Huge Directory
24.14 Don't Use strip Carelessly Book Index 24.16 Trimming a Huge Directory

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