The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
rdcwayx rdcwayx is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 238
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
I need get the folder a/s, but not a/b/c ( because folder b has file), not a/b/x/x.txt (has file in it), not a/s/y (because a/s is already in list).
  #2 (permalink)  
Old 2 Weeks Ago
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,400
do you have "-empty" option in find??
just lokk into man page of find..
  #3 (permalink)  
Old 2 Weeks Ago
rdcwayx rdcwayx is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 238
Quote:
Originally Posted by vidyadhar85 View Post
do you have "-empty" option in find??
just lokk into man page of find..
Thanks, but my system is on Solaris 10, no -empty option.

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?
  #4 (permalink)  
Old 2 Weeks Ago
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,428
What about /usr/xpg4/bin/find
  #5 (permalink)  
Old 2 Weeks Ago
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,538
if your ls has -R,
Code:
ls -1R| nawk '/^\./{s=$0;getline;if($0==""){print "empty: "s}}'
NB:tested on linux, not solaris, but you can give nawk a try. run it on top directory where you want to start searching.
  #6 (permalink)  
Old 2 Weeks Ago
rdcwayx rdcwayx is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 238
Quote:
Originally Posted by ghostdog74 View Post
if your ls has -R,
Code:
ls -1R| nawk '/^\./{s=$0;getline;if($0==""){print "empty: "s}}'
NB:tested on linux, not solaris, but you can give nawk a try. run it on top directory where you want to start searching.
close to my request now. Thank you.

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:
I have more than thousand folders under that folder, I need get the top folder list of

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 ----------

Quote:
Originally Posted by danmero View Post
What about /usr/xpg4/bin/find
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
But if the top folder name include space, the script will not find it out.
  #7 (permalink)  
Old 2 Weeks Ago
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,538
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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0