Sponsored Content
Full Discussion: scanning empty directories
Top Forums UNIX for Dummies Questions & Answers scanning empty directories Post 47707 by Optimus_P on Tuesday 17th of February 2004 10:08:59 AM
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.
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
File::Path(3pm) 					 Perl Programmers Reference Guide					   File::Path(3pm)

NAME
File::Path - create or remove directory trees SYNOPSIS
use File::Path; mkpath(['/foo/bar/baz', 'blurfl/quux'], 1, 0711); rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1); DESCRIPTION
The "mkpath" function provides a convenient way to create directories, even if your "mkdir" kernel call won't create more than one level of directory at a time. "mkpath" takes three arguments: o the name of the path to create, or a reference to a list of paths to create, o a boolean value, which if TRUE will cause "mkpath" to print the name of each directory as it is created (defaults to FALSE), and o the numeric mode to use when creating the directories (defaults to 0777) It returns a list of all directories (including intermediates, determined using the Unix '/' separator) created. If a system error prevents a directory from being created, then the "mkpath" function throws a fatal error with "Carp::croak". This error can be trapped with an "eval" block: eval { mkpath($dir) }; if ($@) { print "Couldn't create $dir: $@"; } Similarly, the "rmtree" function provides a convenient way to delete a subtree from the directory structure, much like the Unix command "rm -r". "rmtree" takes three arguments: o the root of the subtree to delete, or a reference to a list of roots. All of the files and directories below each root, as well as the roots themselves, will be deleted. o a boolean value, which if TRUE will cause "rmtree" to print a message each time it examines a file, giving the name of the file, and indicating whether it's using "rmdir" or "unlink" to remove it, or that it's skipping it. (defaults to FALSE) o a boolean value, which if TRUE will cause "rmtree" to skip any files to which you do not have delete access (if running under VMS) or write access (if running under another OS). This will change in the future when a criterion for 'delete permission' under OSs other than VMS is settled. (defaults to FALSE) It returns the number of files successfully deleted. Symlinks are simply deleted and not followed. NOTE: If the third parameter is not TRUE, "rmtree" is unsecure in the face of failure or interruption. Files and directories which were not deleted may be left with permissions reset to allow world read and write access. Note also that the occurrence of errors in rmtree can be determined only by trapping diagnostic messages using $SIG{__WARN__}; it is not apparent from the return value. Therefore, you must be extremely careful about using "rmtree($foo,$bar,0" in situations where security is an issue. AUTHORS
Tim Bunce <Tim.Bunce@ig.co.uk> and Charles Bailey <bailey@newman.upenn.edu> perl v5.8.0 2002-06-01 File::Path(3pm)
All times are GMT -4. The time now is 06:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy