Tuesday 29 December 2015

Detect & Delete Empty Dir. / Files

---------------------------------------------------
 Lower case file name find & count in CS
---------------------------------------------------

ls | egrep [a-z] |wc -l
ls | egrep [a-z] >> /home/aru.out


------------------------------------------------------
 Find Empty / corrupted file and directories
------------------------------------------------------

cd /home/mr

find . -empty -type d >> /home/D_aru_empty.out
find . -empty -type d | wc -l

find . -empty -type f
find . -empty -type f | wc -l

----------------------------------------------
 Delete Empty File and directories
----------------------------------------------

cd /home/mr

find . -empty -type d -delete
find . -empty -type f -delete

find . -empty -type -d -delete
find . -empty -type -f -delete


------------------------------------------------------------
 find and delete all empty directories using xargs
------------------------------------------------------------

## secure and fast version ###
find /path/to/ -type d -empty -print0 | xargs -0 -I {} /bin/rmdir "{}"


## secure and fast version ###
find /path/to/ -type f -empty -print0 | xargs -0 -I {} /bin/rm "{}"

No comments: