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

I use the watch command to see the contents of my directory changing as a script runs on it (via watch ls dir/)

It's a great tool, except that I can't seem to scroll down or up to see all of the contents once the number of entries fills the vertical length of the screen.

Is there a way to do this?

share|improve this question
up vote 19 down vote accepted

watch is great, but this is one of the things it can't do. You can use tail to show the latest entries:

watch "ls -rtx dir/ | tail -n $(($LINES - 2))"
share|improve this answer
Can you explain why it is necessary to use $(($LINES - 2))" to get the latest entries? – bbaja42 Jun 24 '11 at 20:18
@bbaja42: It fills the screen, leaving a couple of lines for the output of watch itself. $LINES is an automatic variable that Bash and other shells use to contain the number of lines that the screen can display. You could tail any number you want. – Dennis Williamson Jun 25 '11 at 6:00
Can I use the command as is to pipe the output of multiple programs (chained using &&) to tail? – T0xicCode Feb 5 '13 at 20:56
@xav0989: You would need to wrap your chain in curly braces or it will only tail the last command: { command1 && command2 && command3; } | tail - don't forget the spaces (after the opening and before closing brace) and semicolon after the last command. Remember, the whole chain will be executed each time watch reruns it. – Dennis Williamson Feb 5 '13 at 22:50
@DennisWilliamson Awesome thanks – T0xicCode Feb 6 '13 at 17:55

I've created a small program that does exactly what you want in python. Find it here, it's called pwatch.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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