Posted: . At: 10:40 AM. This was 1 year ago. Post ID: 17008
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to list all empty directories on your Linux system.


Listing all empty folders on your Linux system can be very useful, this is how to do this easily. The command below will easily perform this task.

(base) jason@jason-Lenovo-H50-55:~$ sudo find / -type d -empty | sort -u

And how to count all of these unused empty folders.

(base) jason@jason-Lenovo-H50-55:~$ sudo find / -type d -empty | sort -u | wc -l
find: ‘/run/user/1000/gvfs’: Permission denied
5585

This could be a very useful Linux tip indeed.

Convert the output into a csv file.

(base) jason@jason-Lenovo-H50-55:~$ sudo find / -type d -empty | tr '\n' , > directories.csv
find: ‘/run/user/1000/gvfs’: Permission denied

This is how to find directories that contain no other directories, but may or may not contain regular files.

(base) jason@jason-Lenovo-H50-55:/$ sudo find . -type d | sort -r | awk 'index(a,$0)!=1{a=$0;print}' | sort

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.