Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
Is it possible to follow a command (run repeatedly)? as one would follow a file using tail -f?

I would like to monitor files that are being downloaded to a directory in real time on screen in bash.

Is there an easy way in Linux to do the equivalent of tail -f but on a directory, perhaps using ls?

share|improve this question
5  
watch -n1 ls? –  jordanm Sep 11 '12 at 1:34
    
If you want to react to new files being created, what you need is inotify. –  Gilles Sep 12 '12 at 1:38
add comment

marked as duplicate by Gilles, jasonwryan, warl0ck, Renan, Stéphane Gimenez Sep 15 '12 at 16:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

up vote 10 down vote accepted

Use the "watch" command:

watch ls

This will run the "ls" command every 2 seconds.

share|improve this answer
1  
This is the simplest answer that worked. I wanted to add that -n# dictates how often to refresh. eg. watch -n1 ls - will run ls every second and refresh the data on screen. –  T. Brian Jones Sep 11 '12 at 18:48
add comment

Check out inotifywait,

e.g to monitor folder abc, you could do:

while inotifywait -e close_write abc; do
   # do `ls` when abc changed
   ls abc
done
share|improve this answer
    
This will not run the ls until the download has completed (or at least it calls close() on the file). Still, +1 for using inotify. –  jordanm Sep 11 '12 at 2:37
add comment

watch is definitely the best answer if you've got it. But for completeness, you could simulate something crudely similar with a simple bit of shell-script:

while (true)
do
     date
     ls -lrt | tail -n 10
     sleep 2
     clear
done

Another way could be using diff. This one will also point out if files are removed that used to be present. An advantage is it doesn't clear the terminal, so you can see the complete record of all changes by scrolling up. A disadvantage is that it creates two temporary files to manage the state change reasoning.

ls1="/tmp/listing1.dat"
ls2="/tmp/listing2.dat"
ls -lrt > ${ls1}
ls -lrt > ${ls2}

while (true)
do
     diff ${ls1} ${ls2} | grep '[<>]'
     sleep 2
     cp ${ls2} ${ls1}
     ls -lrt > ${ls2}
done
share|improve this answer
add comment

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