A
A
Alexander2020-04-04 10:47:19
linux
Alexander, 2020-04-04 10:47:19

How to find empty folders in linux in terminal?

How to find empty folders in linux terminal and delete them without deleting the child folder?
find /shared/trash/temp/ -empty -type d
Gives the result:
/shared/trash/temp/ - i.e. also a candidate for deletion. folder is empty.

How to avoid deleting the parent folder when it is empty? This task will hang in crontab and delete empty folders and old files in the temp folder

find /shared/trash/temp/ -empty -type d deletes the parent folder too, it doesn't help! And the links are also just the same solution :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Vishnikin, 2020-04-04
@Ic2d

find ./* -type d -empty -exec rmdir {} \; 2> /dev/null
Try

J
jcmvbkbc, 2020-04-06
@jcmvbkbc

How to avoid deleting the parent folder when it is empty?

find /shared/trash/temp/ -mindepth 1 -empty -type d

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question