scanning empty directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scanning empty directories
# 1  
Old 02-17-2004
scanning empty directories

Hi,

I want to produce a text file representing a list of empty directories on a unix system starting from a specified directory.
I hope I explained well my problem.

Thanks in advance.
# 2  
Old 02-17-2004
If you're just looking to delete empty directories, you can use this:
Code:
find . -exec rmdir {} \;

but use it with caution! It'll go ahead and remove all empty directories in the specified path, skipping regular files and directories that contain other files.

As far as just creating a list, I'm not sure...
# 3  
Old 02-17-2004
Quote:
Originally posted by oombera
If you're just looking to delete empty directories, you can use this:
Code:
find . -exec rmdir {} \;

but use it with caution! It'll go ahead and remove all empty directories in the specified path, skipping regular files and directories that contain other files.

As far as just creating a list, I'm not sure...

use -print after the semicolon so you can see a list of the directories you just deleted.
# 4  
Old 02-17-2004
Figured out a better way. Smilie
Code:
find . -type d -links 2 -exec echo '{}' >> somefile \;

# 5  
Old 02-18-2004
Hi Oombera,

thanks for your suggestion.
However, it doesn't seem to work 100%. it returns all the directories, empty or not. I must say, I tried your command on a Iseries (AS400) UNIX shell.
I will try it on a real UNIX (sun solaris) machine.
I'll keep you in touch.

PS. with you it worked well?

Thanks
# 6  
Old 02-18-2004
Quote:
Originally posted by N065956BM
PS. with you it worked well?
Yea - for me it returned only the empty directories. Let me know if it works for you on the solaris machine...
# 7  
Old 02-18-2004
as400 is more mainframe then it is a unix.

as400 commands are really weird, iv only had a brief experiance with as400 when i used to tool around on it when i worked for a school.

it wouldnt surpise me that the find command didnt perform as expected on an as400.

oombera your orig command would work. i am haveing a hard time understanding what the use of the -links 2 is for in this instance. unless a file has 2 links to it it will not be posted.

find . -type d -exec rmdir {} \; -print

this is what you would be looking for.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Empty Directories

Please help me. How i can find empty directories in solaris?? (4 Replies)
Discussion started by: FoDeGe
4 Replies

2. UNIX for Advanced & Expert Users

Delete empty directories recursively - HP-UX

Hi, I want to delete all empty directories in a long directore tree structure. I want to use that from a script that will run on HP-UX 11. My definition of empty directory is that there is no regular file under it and directly beneath it. To elaborate, I have below directories. /app/dev/java... (14 Replies)
Discussion started by: asutoshch
14 Replies

3. Shell Programming and Scripting

How to exclude the empty directories

Hi., I have a script, in which I am processing a files present in the directory types. ls -lrt | grep ^d | grep Dir_type | awk -f '{print $9}' |\ while read dir_name; do #operations done where Dir_type is the pattern in which directories get created. How to filter out empty... (2 Replies)
Discussion started by: IND123
2 Replies

4. Shell Programming and Scripting

Deleting empty directories using find

Hello, I'm submitting this thread, because I was looking a way to delete empty directories using find and I found a thread from 2007 that helped me. I have worked from that threat, but I found that the command sent would analyze original directory and may delete it to. I have come up with expanded... (3 Replies)
Discussion started by: lramirev
3 Replies

5. Shell Programming and Scripting

Listing non empty directories

Hi Gurus, How to list directories that are non-empty and non-hidden Thanks in advance (2 Replies)
Discussion started by: kinny
2 Replies

6. UNIX for Dummies Questions & Answers

Remove only Empty Directories

I know this one was answered before in forum below - https://www.unix.com/unix-dummies-questions-answers/58210-removing-empty-folders-using-find-command.html But that one is closed & I have a question so here it goes. I want to delete all 2006 files. Now if along with the files, if the... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

7. Shell Programming and Scripting

identify the empty directories

Hi Wrote the below script to identify the empty directories ,when executing the below showing that directory is not empty but the directories are empty.Please help to identify the empty directories 33 is not empty 33 is not empty 33 is not empty 33 is not empty for file in `find .... (5 Replies)
Discussion started by: mohan705
5 Replies

8. UNIX for Dummies Questions & Answers

Empty directories having different size

$ls -lrt mydir total 12 drwxrwxrwx 2 nobody nobody 512 Aug 8 11:51 tmp drwxrwxrwx 2 nobody nobody 4608 Jan 19 12:20 web.cache $ ls -lrt mydir/web.cache/ total 0 $ ls -lrt mydir/tmp/ total 0 Can anyone explain me the above results? I know the o/p of ls, but this... (3 Replies)
Discussion started by: rahulrathod
3 Replies

9. UNIX for Dummies Questions & Answers

Help identifying empty directories

Is there a way you can identify directories that are empty? I do not need to remove them, I just need to identify them below a cetain path. I have tried the following already and it returned everything for some reason. #!/bin/sh && set -- . find "$@" -type d -depth -print > dir.txt |... (2 Replies)
Discussion started by: dboard
2 Replies

10. Shell Programming and Scripting

searching for list of empty directories

Guys I need to write a korn shell script that will search for a list of empty sub-directories in a specific directory and then email a list of these empty directories. Any ideas - apologies, I am new to shell scripting. Thanks (4 Replies)
Discussion started by: man80
4 Replies
Login or Register to Ask a Question