Re: how to write a script that recursively check files in a directory with md5sum
Sturla Holm Hansen wrote:
BTW, what are all those files in your home directory? I have only
about 14000 and thought that this is the biggest mess ever ;)
Oh, stuff. source of debs, built and otherwise. CVS checkouts of
stuff. Documents. Photos (see my sig for some). IBM operating systems.
Lotsa stuff. 12 Gbytes of stuff. Too much stuff.
Since I'm kinda new at this I just have to ask what's wrong with a
for-loop..
To slow?
I have no idea, but I use something like this to recurse down a tree and
do something with every file:
#!/bin/bash
for i in `find -type f`
do
whatever you wan't to do, just use $i instead of the filename.
done
It's slower than find .. exec.
However, if I did this:
for f in `find ~'
etc
it would blow up with a too-long commandline. That's why xargs is so
useful: it knows what the limit is and works around it.
If you want to do lotsa stuff to lotsa files you have two choices:
1. Write a script that does lotsa stuff to all the files mentioned on
its commandline, and invoke it with the semanitcs I've been recommending or
2. Write a script like this:
find ~ -type f | while read stuff
do lotsa stuff
done.
Both approaches have their placees.
btw I prefer this:
for f in $(find ~ -type d -depth)
over this:
for f in `find ~ -type d -depth`
Read the man page to find what -depth does. I embarrassed myself over
that too.
--
Cheers
John
-- spambait
1aaaaaaa@computerdatasafe.com.au Z1aaaaaaa@computerdatasafe.com.au
Tourist pics http://portgeographe.environmentaldisasters.cds.merseine.nu/
Reply to: