Saturday, April 27, 2024
149
rated 0 times [  149] [ 0]  / answers: 1 / hits: 85465  / 1 Year ago, tue, may 16, 2023, 4:03:49

Say I have a directory named foo/. This folder includes subdirectories. How can I delete all the empty directories in one command?


More From » command-line

 Answers
2

Try this command:



find . -empty -type d -delete


The find command is used to search for files/directories matching a particular search criteria from the specified path, in this case the current directory (hence the .).



The -empty option holds true for any file and directory that is empty.



The -type d option holds true for the file type specified; in this case d stands for the file type directory.



The -delete option is the action to perform, and holds true for all files found in the search.


[#42444] Thursday, May 18, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
otputler

Total Points: 53
Total Questions: 105
Total Answers: 93

Location: Zimbabwe
Member since Wed, Nov 9, 2022
2 Years ago
otputler questions
Tue, Aug 23, 22, 14:36, 2 Years ago
Fri, Jul 23, 21, 11:57, 3 Years ago
Sun, Feb 12, 23, 18:37, 1 Year ago
;