10-20-2009
Remove only Empty Directories
I know this one was answered before in forum below -
https://www.unix.com/unix-dummies-que...d-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 folder is even older (2006) then it should be deleted as well - if it has all 2006 files.
so how I do it?
1) Deleted 2006 - old files. -- DONE without any issues.
2)
Delete All Empty folders left after Step #1
Quote:
find ./ -type d -depth -mtime +1052 –print| xargs rm –f
But here is what I get -
$: find ./ -empty -type d
find: bad option -empty
find: path-list predicate-list
I dont wanna experiment on my PROD environment with below command -
Quote:
find ./ -type d -exec rmdir 2>/dev/null {} \;
This ideally deletes all the directories but gives warning before deleting it. Tricking it is a good idea, but not sure how my OS will behave (Sun Solaris Unix).
Is writing a script only way to get it done in that case?!!
Anyhelp will be appreciated.
Thanks,
Ked[COLOR="#738fbf"]
Last edited by kedar.mehta; 10-20-2009 at 04:08 PM..
Reason: Trying to avoid bumping up the post
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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. (7 Replies)
Discussion started by: N065956BM
7 Replies
2. UNIX for Dummies Questions & Answers
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
$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
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. Shell Programming and Scripting
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. Shell Programming and Scripting
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
7. Shell Programming and Scripting
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
8. UNIX for Advanced & Expert Users
Hi Gurus,
I have command to delete more than 180days file.
find /home/abc/ -name "CBST_*.txt*" -mtime +180 | xargs -n 100 rm -f
Now I would like to delete more than 180days Non empty directory--What will be command?
Following is non empty directory as instance CBST2010* (2 Replies)
Discussion started by: thepurple
2 Replies
9. UNIX for Advanced & Expert Users
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
Please help me. How i can find empty directories in solaris?? (4 Replies)
Discussion started by: FoDeGe
4 Replies
LEARN ABOUT CENTOS
file::remove
File::Remove(3) User Contributed Perl Documentation File::Remove(3)
NAME
File::Remove - Remove files and directories
SYNOPSIS
use File::Remove 'remove';
# removes (without recursion) several files
remove( '*.c', '*.pl' );
# removes (with recursion) several directories
remove( 1, qw{directory1 directory2} );
# removes (with recursion) several files and directories
remove( 1, qw{file1 file2 directory1 *~} );
# trashes (with support for undeleting later) several files
trash( '*~' );
DESCRIPTION
File::Remove::remove removes files and directories. It acts like /bin/rm, for the most part. Although "unlink" can be given a list of
files, it will not remove directories; this module remedies that. It also accepts wildcards, * and ?, as arguments for filenames.
File::Remove::trash accepts the same arguments as remove, with the addition of an optional, infrequently used "other platforms" hashref.
SUBROUTINES
remove
Removes files and directories. Directories are removed recursively like in rm -rf if the first argument is a reference to a scalar that
evaluates to true. If the first arguemnt is a reference to a scalar then it is used as the value of the recursive flag. By default it's
false so only pass 1 to it.
In list context it returns a list of files/directories removed, in scalar context it returns the number of files/directories removed. The
list/number should match what was passed in if everything went well.
rm
Just calls remove. It's there for people who get tired of typing remove.
clear
The "clear" function is a version of "remove" designed for use in test scripts. It takes a list of paths that it will both initially delete
during the current test run, and then further flag for deletion at END-time as a convenience for the next test run.
trash
Removes files and directories, with support for undeleting later. Accepts an optional "other platforms" hashref, passing the remaining
arguments to remove.
Win32
Requires Win32::FileOp.
Installation not actually enforced on Win32 yet, since Win32::FileOp has badly failing dependencies at time of writing.
OS X
Requires Mac::Glue.
Other platforms
The first argument to trash() must be a hashref with two keys, 'rmdir' and 'unlink', each referencing a coderef. The coderefs will be
called with the filenames that are to be deleted.
SUPPORT
Bugs should always be submitted via the CPAN bug tracker
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Remove>
For other issues, contact the maintainer.
AUTHOR
Adam Kennedy <adamk@cpan.org>
COPYRIGHT
Some parts copyright 2006 - 2012 Adam Kennedy.
Taken over by Adam Kennedy <adamk@cpan.org> to fix the "deep readonly files" bug, and do some package cleaning.
Some parts copyright 2004 - 2005 Richard Soderberg.
Taken over by Richard Soderberg <perl@crystalflame.net> to port it to File::Spec and add tests.
Original copyright: 1998 by Gabor Egressy, <gabor@vmunix.com>.
This program is free software; you can redistribute and/or modify it under the same terms as Perl itself.
perl v5.16.3 2012-03-19 File::Remove(3)