Monday, January 31, 2022

[SOLVED] find directories

Issue

I have been trying to get to count all the empty folders in a certain directory. sub-directories excluded. i used the code below but i don't know how to define empty folders or folders that contain files.

echo "$(ls -l | egrep -l $1/* | wc -l)"

the $1 will be the user argument in the command line. example: ./script.sh ~/Desktop/backups/March2021.

Edit - im not allowed to use find command

Edit 2 - ls -l * | awk '/total 0/{print last}{last=$0}' | wc -l this script works but lists all folders even if the directory contains files and data or if the directory is empty.


Solution

What about this:

grep -v "." *

I mean the following: "." means any character (I'm not sure the syntax is correct), so basically you look for every file which not even contain any character.



Answered By - Dominique
Answer Checked By - Senaida (WPSolving Volunteer)