![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing empty folders using 'find' | deTTo | UNIX for Dummies Questions & Answers | 5 | 04-21-2008 10:24 PM |
| Removing empty folders using the "find" command | biot | UNIX for Dummies Questions & Answers | 3 | 03-25-2008 10:43 PM |
| how to find empty folders without using -empty | lasse | UNIX for Dummies Questions & Answers | 7 | 01-17-2008 02:30 AM |
| zip nesting empty folders | groundlevel | UNIX for Dummies Questions & Answers | 0 | 09-29-2006 12:08 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Find empty folders
In current folder, there are many subfolders, subfolder's subfolders... under it.
How can I find out the empty folders with no files in it. I only need the top folder list. For example, I have folders like below: Code:
a/b/c a/b/x/x.txt a/s a/s/y |
|
||||
|
Quote:
Seems I have to install a GNU find to get it done. my another idea is to install CYGWIN (which I already have, and find command with -empty), map the Solaris driver by SAMBA. I can see the driver in windows explorer, but I can't see the driver in cygwin. Any suggestion on it? |
|
||||
|
Quote:
But it doesn't report the top folders only. In sample, Code:
$ ls -1R| nawk '/^\./{s=$0;getline;if($0==""){print s}}'
./a/b:
./c:
Code:
./a (because under folder a, only have subfolder b, no any files.) ./c ---------- Post updated at 10:02 PM ---------- Previous update was at 10:00 PM ---------- same error, not support -empty. ---------- Post updated at 10:12 PM ---------- Previous update was at 10:02 PM ---------- Get it by myself Code:
for i in `ls -l |awk '{if ($1~/^d/) print $9}'`
do
if [ "$(find $i -type f)" = "" ] ; then
echo $i "is empty folder"
fi
done
|
|
||||
|
don't get a file name like that using ls -1 and print column 9. if you have spaces in the file name , you will not get the correct file name. Use find instead, then something to count inside each directory. Pseudocode
Code:
find . -type d | while read DIR do var=`ls $DIR | wc -l ` if var is 0 then echo "empty" fi done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|