Unix/Linux Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

how to find empty folders without using -empty

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-16-2008
lasse lasse is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 17 January 2008, 12:50 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
how to find empty folders without using -empty

hi all:
my solaris FIND does not support

Code:
find myFolder -type d -empty

how can i find the empty folders?
thanks!
Sponsored Links
    #2  
Old Unix and Linux 01-16-2008
abanna abanna is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 20 January 2009, 7:53 AM EST
Location: cairo
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
du -ks * | sort -n

Result like that:

Size Dir Name
0 DEACT_TOTO

--------------------

Or

ls -ltr | grep "^d" | awk '{print $9}' | xargs -i du -ks {} | sort -n
Sponsored Links
    #3  
Old Unix and Linux 01-16-2008
lasse lasse is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 17 January 2008, 12:50 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
mkdir aa1 aa2
du -ks * |sort -n

the result is
1 aa1
1 aa2

and i TOUCH a new file in aa1, run again, the result still:
1 aa1
1 aa2

-size 0 can not work for empty folder
    #4  
Old Unix and Linux 01-16-2008
lasse lasse is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 17 January 2008, 12:50 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hi all, does this code do the job?

Code:
#!/bin/ksh
find myfolder -type d|while read name
do
if (( $(ls -al $name|wc -l) == 3 ))
then
echo $name
fi
done

Sponsored Links
    #5  
Old Unix and Linux 01-16-2008
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts
Quote:
Originally Posted by lasse View Post
Hi all, does this code do the job?

Code:
#!/bin/ksh
find myfolder -type d|while read name
do
if (( $(ls -al $name|wc -l) == 3 ))
then
echo $name
fi
done

try it out on the command line.
Sponsored Links
    #6  
Old Unix and Linux 01-16-2008
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts

Code:
# ls -l * | awk '/total 0/{print last}{last=$0}'

Sponsored Links
    #7  
Old Unix and Linux 01-17-2008
lasse lasse is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 17 January 2008, 12:50 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ghostdog74 View Post
try it out on the command line.
HI,
i wrote it and have tested but want someone to confirm.
thxUnix or Linux Image
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing empty folders emveedee UNIX for Dummies Questions & Answers 2 06-18-2011 08:00 AM
Find empty folders rdcwayx Shell Programming and Scripting 6 11-09-2009 10:34 PM
Removing empty folders using 'find' deTTo UNIX for Dummies Questions & Answers 5 04-21-2008 09:24 PM
Removing empty folders using the "find" command biot UNIX for Dummies Questions & Answers 3 03-25-2008 10:43 PM
zip nesting empty folders groundlevel UNIX for Dummies Questions & Answers 0 09-28-2006 11:08 PM



All times are GMT -4. The time now is 03:21 PM.