Assuming you have a complex filesystem from which you want to delete all empty directories and all directories containing empty directories recursively, while leaving intact the rest.
You can use the following command.
find . -type d -empty -delete;
The configuration we used is the following:
-type d restricts the results to directories only
-empty restricts to empty directories only
-delete removes the directories that matched
The above code will delete all directories that are either empty or contain empty directories in the current directory.
It will successfully delete all empty directories even if they contain a large number of empty directories in any structure inside them.
Since you are searching for this issue, you must have realised that git does not support storing empty folders/directories. Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about…
Following you will find some tests one can perform on a file to identify its state Check if file $FILE does not exist if [ ! -f "$FILE" ]; then echo "File $FILE does not exist"; fi Check if file $FILE exists and is a directory if [ -d "$FILE"…
Scenario You have a complex folder structure and you want to remove all files and at the same time keep all folders intact. We will present one method, using two variations of it that can achieve the above. The method uses the GNU find command to find all files and…