Similar to my last question: Open a text file and let it update itself; is there a way I could do the same but for a folder instead?

As I have a log folder, can I use tail -f with a folder?


$ tail -f /tmp/logs/

I know that this won't work, but is there an alternative?

I am using RHEL 5.10

  • tail -f /tmp/logs/* should work – yegle Sep 13 '14 at 5:36

Yes there is an alternative, after a bit of research, I saw that you can use:

$ watch "ls -l"

You need to be in the folder you want to watch.

Also, you can use tail -10 at the end:

$ watch "ls -l | tail -10"

The command types ls every 2 seconds and filters the output to the last 10 files.

If you read the reference link, it has some great tips, also if you can't remember the above command, then you can add the following to your .bashrc file:

alias taildir='watch "ls -l | tail -10"'

So you can just type taildir instead of writing the full command out again.

Reference: How to Tail A Directory.

  • 2
    If using with tail, I guess it would make sense to use ls -lrt, so the last few files are always the ones which changed last. EDIT: After following your link, I've seen that this is exactly what is done there. – celtschk Sep 12 '14 at 15:24
  • @celtschk: I saw that the webpage was using -lrt, but what does the rt stand for? The only ones I have used are: ls -l and ls -la. – Kevdog777 Sep 12 '14 at 15:25
  • 1
    rreverse sort, t sort by time; the result is that newest files are at bottom thus kept by tail. – AProgrammer Sep 12 '14 at 15:30
  • 2
    Probably an even better idea would be watch "ls -lt | head -11"; this would show not only the ten newest files, but in addition the total size of the files in the directory. – celtschk Sep 12 '14 at 15:37

I'm not sure what do you want exactly. Maybe you need inotifywait from inotify-tools package (in Ubuntu). This is linux-only solution, unfortunately. For example:

$ inotifywait -m -e create -e modify -r /var/log
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
/var/log/ CREATE test-for-inotify1.txt
/var/log/upstart/ CREATE test-for-inotify2.txt
/var/log/ MODIFY test-for-inotify1.txt
/var/log/ MODIFY auth.log
/var/log/ MODIFY syslog
/var/log/ MODIFY auth.log

See man 1 inotifywait for more watching events and options.


Also, if you need monitoring only some certain files you can use tail -f with several file names:

$ tail -f 1.txt 2.txt 3.txt
==> 1.txt <==

==> 2.txt <==

==> 3.txt <==

==> 1.txt <==
new string in 1.txt

==> 3.txt <==
add string to 3.txt

==> 2.txt <==
And to 2.txt
  • Sorry I forgot to mention what System I am running on. I have updated my question. Will this still work with RHEL 5.10? I was also looking for a way similar to tail -f, so I kept along the lines of using tail. Thanks though. – Kevdog777 Sep 12 '14 at 15:47
  • Yes, it should work in RHEL. If this package absence in standart repositories, you can find it by other ways - rpmseek.com/rpm-pl/inotify-tools.html?hl=com&cx=0:: – loooser Sep 12 '14 at 15:54
  • What exactly you want to see? Every new line in each file on the directory? What about new lines in new files? – loooser Sep 12 '14 at 15:58
  • All I want to see is if there is a new file shown. i.e. As I am running Apache, I have a service that might write to a log file - but I don't know when that will be, and I don't have the time to sit here and keep refreshing the folder. It's only two files anyways. – Kevdog777 Sep 12 '14 at 16:02
  • See addition to my answer - Is you wanted this? – loooser Sep 12 '14 at 16:24

How about this command without the need of watch or inotify?

ls -drt /var/log/* | tail -n5 | xargs tail -F

tail -n5 finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files. However, you could remove this if you need to monitor all the files in eral time.


Follow the most recently updated log files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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