Display only non-empty directories with the ls command

1

Hello,

I'm a beginner in Ubuntu and would like to know if there is any way to display only directories that contain subdirectories or files on the command line. If I type only ls , there are directories, executable and non-executable files grouped by color. I would like only the non-empty directories to appear. Thanks!

    
asked by anonymous 25.02.2016 / 22:31

2 answers

2

Use:

find . -mindepth 1 -maxdepth 1 -not -empty -type d

Where . is the path to the directory you want to list, in which case it is looking in the current directory.

    
25.02.2016 / 22:43
1

You can use the following commands:

find ~/meuDiretorio -not -empty -type d -ls

The above command will only list the folders that have some content.

The find command is for searching folders and files, the -not option means deny, in this case it is to invert the return of the -empty option which is to specify empty files or folders, and the option -type is to specify a type you want, the type defined was directories through the d option passed to -type , and it would be as a filter type, and finally the -ls option that is responsible for getting some more information , and in this context it is an option of the command find , you can remove it if you want to see only non-empty directories.

The character ~ indicates your home folder, example /home/usuario , you can change it if you want.

Sources:
How can I list only non-empty files using ls ?: link
Find command manual: link

    
25.02.2016 / 23:50