I was wondering if there's any way to display some kind of progress info when searching for files in linux using find. I often find myself searching for files on a big disk and some kind of progress indicator would be very helpfull, like a bar or at least the current directory "find" searches in. Are there any scripts that do that, or does find support some hooks?

link|improve this question
thanks for the edit – Vlad Dec 15 '11 at 8:21
thanks for the answers, i'll check all the solutions and decided which one is better. If it were up to me i would mark all the answers as accepted. – Vlad Dec 15 '11 at 12:01
depending on which search criteria youb are using locate is much more faster than find – B14D3 Dec 15 '11 at 14:34
feedback

4 Answers

up vote 5 down vote accepted

with this trick you can see the current folder - but no progress bar - sorry.

 watch readlink -f /proc/$(pidof find)/cwd
link|improve this answer
that's cool. Should be noted thou that you need superuser privileges in order to access cwd. thanks! – Vlad Dec 15 '11 at 12:15
feedback

AFAIK, it doesn't, and implementing it would be nontrivial.

... Hmm. Perhaps a script running find <target dir> -type d first, storing the list and then echoing each dir before running a find <list item> -maxdepth 1 <rest of find parameters> in a for loop.

Note that you're trading a /significant/ loss of performance in exchange for being able to vaguely see what it's doing.

link|improve this answer
feedback

There's an example of parallel searches with find in man find. Using it, you can perform multiple checks for every item, performing multiple actions depending on which condition works. The first check may be, for example, simple-print, so all names are printed to stdout. The second check will do what you want. Something like:

find /work \( -fprint /dev/stderr \) , \( -name 'core' -exec rm {} \; \)

If the second check should display filenames, too, you can redirect one of them to stderr using -fprint /dev/stderr.

link|improve this answer
feedback

A little utility called pv (pipe viewer) may help. From the fantastic summary by Peteris Krumins:

Pipe viewer is a terminal-based tool for monitoring the progress of data through a pipeline.

You can use pv in a number of ways. When playing around here, I put it immediately after a pipe to monitor progress of the output generated by find (should pass stdin to stdout untouched)

find / -mtime -1h | pv > /dev/null

(I redirected stdout to /dev/null so I could see the progress bar in action without output flying by. This is likely not your intent with find, so tailor accordingly)

I'm honestly not sure how well this works in the wild. For "expensive" finds like the one above (traversing from root), it appeared to work fairly well. For simpler commands in a deeper node in the directory tree, pv failed miserably. These commands are returning results immediately, so a progress bar is probably moot here.

At any rate, play around and see if this works at all for what you need. Food for thought, at least.

link|improve this answer
What would that progress bar show? Neither find, nor pv know how long the search will take,, so they cannot compute the percentage. All we can see in the pv output is the time since the search was started. – minaev Dec 15 '11 at 10:02
This is correct. I had thought there was some magic going on, somewhere, that allowed pv to check the progress of the directory traversal (which is incorrect). Given standard input at a constant rate, pv simply moves the progress bar at a constant frequency. Try yes | pv > /dev/null to observe – tcdyl Dec 15 '11 at 10:07
+1 for a nice utility – Vlad Dec 15 '11 at 12:26
feedback

Your Answer

 
or
required, but never shown

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