To get an ls -l format list of empty directories in the file system mounted on the mount point /MountPoint on a Solaris system, try:
---
Update... And, if you just want the names of the empty directories, you could also try:
Last edited by Don Cragun; 11-29-2016 at 09:15 PM..
Reason: Simplify 1st suggestion.
This User Gave Thanks to Don Cragun For This Post:
Don, your suggestion is not correct.
In Unix the link count of a directory is increased if sub directories are added, but not if files are added.
The plausible reason is that a directory is linked to . and .. plus every sub directory's ..
So, an empty directory has always got a link count 2, but not vice versa.
--
For the request to find/list empty directories the straight answer is GNU find
With the native Solaris find it becomes more complicated. For example
The -links 2 condition is useful - it reduces the calls to /bin/sh and ls. Still much overhead. A solution in perl with it's built-in lstat() would be more efficient...
This User Gave Thanks to MadeInGermany For This Post:
Don, your suggestion is not correct.
In Unix the link count of a directory is increased if sub directories are added, but not if files are added.
The plausible reason is that a directory is linked to . and .. plus every sub directory's ..
So, an empty directory has always got a link count 2, but not vice versa.
--
For the request to find/list empty directories the straight answer is GNU find
With the native Solaris find it becomes more complicated. For example
The -links 2 condition is useful - it reduces the calls to /bin/sh and ls. Still much overhead. A solution in perl with it's built-in lstat() would be more efficient...
Not on the systems I have used and not according to the standards. The link count on a directory is the number of links in that directory (one for every file no matter what type of file it is); for a regular file it is the number of hard links to that file; and for other file types it can vary. Depending on filesystem type, a directory need not include links for dot and dot-dot, but for the VAST majority of filesystem types that are usually mounted on Solaris systems, those links are included and the link count on an empty directory will be 2. In theory, we should determine the filesystem type for every directory mounted, create an empty directory and determine if the link count on that directory is 0 or 2 and use that number when doing the find on that filesystem's mount point; in practice, on any system I've used, 2 works. I'm on a macOS 10.12.1 system now. Here is the output from ls -lRa .:
Note that the link count on a is 3 (dot, dot-dot, and b are those three links. The link count on a/b is 6 (dot, dot-dot, c, and the three regular files f1, f2, and f3. And, the link count on a/b/c (an empty directory) is 2 (dot and dot-dot).
This User Gave Thanks to Don Cragun For This Post:
Hmm, interesting. Also Solaris zfs is like this.
But Solaris ufs,vxfs, AIX jfs2, Linux ext3,ext4,xfs are using the other scheme (traditional Unix I assume).
This User Gave Thanks to MadeInGermany For This Post:
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)
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)
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)
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)
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)
$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)
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)
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)
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)