Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I search all empty files of non-root system and delete them?

share|improve this question

migrated from stackoverflow.com Apr 3 '11 at 23:07

This question came from our site for professional and enthusiast programmers.

    
Saying "Unix" is very vague. There are many unix-like OSs. You should specify the actual OS. –  Wuffers Apr 3 '11 at 23:15

2 Answers 2

find /path/to/mountpoint -empty -type f -delete

If your find does not have -delete option, replace it with -exec rm '{}' ';'

If you want to delete all empty files except for files directly under / run:

find / -mindepth 2 -empty -type f -delete

If you want to delete all empty files, but skip whole /root directory run

find / \( -path /root -prune \) -empty -type f -delete
share|improve this answer
    
i want to say that / includes many directories between them there is the root ,so i want to execute a find command on all the empty files on / except those on the root directory ? –  maalem Apr 2 '11 at 21:27
    
You mean you want to skip /root from cleaning? If so, I modified my answer. If not so, please give an example. –  Piotr Findeisen Apr 3 '11 at 6:58

find . -size 0 -print.

replace -print with -delete and . with the directory you need, but execute carefully, it will really delete all empty files.

share|improve this answer
    
thanks, but i want to remove also all empty files of non root directory ,and not in a specific directory ? –  maalem Apr 2 '11 at 20:46
    
how can i execute that command on all the files except those on the root directory ? –  maalem Apr 2 '11 at 20:56
    
@maalem: you can specify multiple directories instead of .. They can a result of another find, not sure how to specify the depth to find dirs in the root dir only (have no chance to test now, try man find). –  khachik Apr 2 '11 at 21:04
    
@maalem, @khachik, i modify the answer to reflect your comments here (if i understood your intent correctly...) –  Piotr Findeisen Apr 2 '11 at 21:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.