Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List non empty directories

Tags:

r

Is there any easy way to list only directories that are not empty?

I am aware of list.dirs but I couldn't find the way to list only directories that are not empty.

like image 527
user2380782 Avatar asked Nov 09 '16 21:11

user2380782


People also ask

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 rm to a non-empty directory?

For empty directories, use rmdir [dirname] or rm -d [dirname] For non-empty directories, use rm -r [dirname]

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.

What is a non-empty directory?

The non-empty directory means the directory with files or subdirectories. We can delete the directory by using the Delete() method of the Directory class.

How do I list empty folders?

Use the 'find' command along with the '-type' flag that specifies the directory type search using the keyword 'd'. The word '-empty' has been used as a flag to search only empty directories within the home directory as stated below. The dot means the current location which is the home directory of a Linux-based system.


1 Answers

Get filenames then extract directory name:

unique(dirname(list.files(full.names = TRUE, recursive = TRUE)))
like image 190
zx8754 Avatar answered Sep 30 '22 17:09

zx8754