Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Directories With No Files in Unix/Linux

Tags:

linux

find

unix

I have a list of directories

/home
  /dir1
  /dir2
  ...
  /dir100

Some of them have no files in it. How can I use Unix find to do it?

I tried

find . -name "*" -type d -size 0 

Doesn't seem to work.

like image 896
neversaint Avatar asked May 26 '10 01:05

neversaint


People also ask

How do you find no of files in a directory in Unix?

To determine how many files there are in the current directory, put in ls -1 | wc -l. This uses wc to do a count of the number of lines (-l) in the output of ls -1.

How find non empty directory in Linux?

Finding Non-Empty Files Only Under the Given Directory As we've learned, find will search recursively under the given directory by default. If we want the find command only to scan the given directory, we can pass the -maxdepth 1 option.

How do I list empty directories in Linux?

Empty dirs in current dir: find . -type d -empty . In addition, empty files: find . -type f -empty in current dir and deeper.

How do I view empty files in Unix?

-type f : Search and list files only. -type d : Find and list empty directories only. -empty : Only list empty files or folders on Linux or Unix. -ls : Show current file in ls -dils format on your screen.


1 Answers

Does your find have predicate -empty?

You should be able to use find . -type d -empty

like image 185
David M Avatar answered Sep 23 '22 10:09

David M