LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Linux script that reads thru folders and execute command (http://www.linuxquestions.org/questions/linux-general-1/linux-script-that-reads-thru-folders-and-execute-command-4175451121/)

vdamgo 02-21-2013 09:25 AM

Linux script that reads thru folders and execute command
 
how to write a script that reads thru the bunch of folders using while loop.
Please let me know.

Thanks!

schneidz 02-21-2013 09:31 AM

where are you stuck ?
i would use the find command to get a list of the directories then pipe it into whatever program i would want to run. the basic structure would be:
Code:

while read line
do
 something $line
done


vdamgo 02-21-2013 09:39 AM

Thank you for the reply.

I have one command as below which will sum the file size in each folder, want to execute in 50 folders and get the size of all folders. instead of executing the command in each folder.

find . -type f -newer folder1 -not -newer folder2 -printf "%s\n" | awk '{sum += $0} END{print sum}'

schneidz 02-21-2013 09:47 AM

Quote:

Originally Posted by vdamgo (Post 4896740)
Thank you for the reply.

I have one command as below which will sum the file size in each folder, want to execute in 50 folders and get the size of all folders. instead of executing the command in each folder.

find . -type f -newer folder1 -not -newer folder2 -printf "%s\n" | awk '{sum += $0} END{print sum}'

not really sure from your description what you are after but heres my stab at it:
Code:

find . -type d | while read dir
do
 find "$dir" -type f -newer "$dir"/folder1 -not -newer "$dir"/folder2 -printf "%s\n" | awk '{sum += $0} END{print sum}'
done



All times are GMT -5. The time now is 01:22 PM.