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.

I like the watch command, but it has its limitations.

I'm curious to know whether I could mimic the functionality of watch with less. I'm mainly looking for the ability to scroll through my directory as it dynamically gets modified via a running script.

share|improve this question
add comment

7 Answers

up vote 22 down vote accepted

There's no good way to do this in less. You can type F to keep reading at the end of a file (like tail -f). You can type :e and a file name to view a different file, but unfortunately, if you enter the name of the current file, less doesn't reload the file.

If you're looking for an alternative to watch ls, here are a few:

  • Modern file managers (e.g. Nautilus, Thunar, Konqueror, Dolphin, Finder) refresh views in real time.
  • Emacs doesn't have real-time refresh, but with auto-revert-mode, it will reload the file or directory every 5 seconds (the delay is configurable).
  • Although w3m is primarily a web browser, it makes a passable directory and text file viewer. Press R to reload the (local) URL.
share|improve this answer
add comment

Simply type:

less +F filename

This emulates pressing "F" within the editor.

share|improve this answer
add comment

I normally use shift+G,shift+G to tail the output, or file, on a one-time basis. I find it especially helpful over a a network file system like CIFS.

share|improve this answer
add comment

You can use vim to read the file then add the following mapping to your .vimrc file and you can easily reload a file with ,r:

let mapleader = ","
nnoremap <leader>r :edit <CR>

Note if you edited the file already, vim will complain. Just change to

let mapleader = ","
nnoremap <leader>r :edit! <CR>

To ignore changes.

share|improve this answer
add comment

Shift+F will make less similar to tailf. That is, it gets refreshed if more data is appended to the file.

share|improve this answer
add comment

You could pipe it to tail -f instead, it would result in you following the output. You'd be losing the ability to move (scroll) through your output though.

share|improve this answer
add comment

The "F" key when running less will do a "follow" similar to tail -f, but I'm not sure if that will achieve what you're looking for here.

share|improve this answer
add comment

Your Answer

 
discard

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.