Skip to content
Advertisement

How to delete a subfolder with only a single file under the parent folder [closed]

I have a folder with 8000 subfolders, and want to delete those subfolders that only contain one file

Advertisement

Answer

Considering all of the subfolders are in the same folder with no “sub-sub” depth, find command prints subfolders with this one-liner and bash handles the rest:

Sample folder and files:

JavaScript

One liner to remove subfolders containing only one file:

JavaScript

List of what is remained after removing

JavaScript

Extra

List of subfolders with the number of files included:

JavaScript

List of subfolders containing only one file:

JavaScript
Advertisement