Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to select all the subdirectories in a given folder that have a certain number (in this case, 75) files within them. Then I want to take the name of each of these subdirectories and assign it a new variable name to use throughout the rest of my script.

Thank you!!

share|improve this question
1  
What have you tried...? –  nerdwaller Oct 2 '13 at 21:30
    
Do you want to count sub sub directories as well or only files? What about files in sub sub sub directories? What have you got so far? We won't write the script for you but would be happy to help out with a specific problem. Please read How to Ask. –  terdon Oct 2 '13 at 22:20
add comment

1 Answer

Here an idea.

filecount is the number of files you want to find. For each folder with this number of files, a variable will be created. The variable-name is the folder-name but the "/" were substituted by "_"

filecount=1
for i in find folder -type d
do
count=ls $i|wc -l
if [ $count -eq $filecount ]
then
export echo $i | sed -e "s/\//_/g"=ls -d $PWD/$i
fi
done
env | grep folder

Regards chris

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.