Quote:
Originally Posted by trintukaz
I don't know what to do
Code:
#!/bin/bash
for i in `find /home/arturas -type d`
do
find -type f | wc -l
done
Trying something like this.
|
The
for i in `find /home/arturas -type d` implements David the H's first step, "Make a list of directories". It will bork on directory names with spaces in their names etc. but let's not get distracted by that yet.
The second step is "Determine the number of files in each directory".
find -type f | wc -l is going in the right direction but you need to tell it the starting directory (otherwise it starts from the current directory) and to tell it not to look in any subdirectories.
find's -maxdepth option is what you need.
BTW, when not familiar with the commands to put in a script it's helpful to run them at the command prompt to explore what they do.
The script will need to keep the number of files in each directory and the directory name. It could keep them in a variable but if there are a lot of directories the script will run slowly and writing them to a temporary file would allow the script to run faster. The >> redirection operator is good for that.
When scripts become large, it is very helpful to have meaningful variable names so
for dir in `find /home/arturas -type d` would be a good choice.
Please post back how you got on with these hints.