Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to select all the sub-directories 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 sub-directories and assign it a new variable name to use throughout the rest of my script.

share|improve this question
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

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 "_"

for i in `find folder -type d`
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
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .