Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.

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
up vote 18 down vote accepted

Use the "watch" command:

watch ls

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

share|improve this answer
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

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)
     ls -lrt | tail -n 10
     sleep 2

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.

ls -lrt > ${ls1}
ls -lrt > ${ls2}

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

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
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

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