Hot answers tagged

50

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. However there's a trick to make it re-read the current file, suggested by sabgenton: type :e and enter the name of a non-existent ...


44

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


32

There is watch in cygwin. But it isn't installed by default. You need to install procps package to appear watch. (you can run cygwin installer again and it allows to install only the missed packages without reinstalling the whole cygwin) Instead of watch you can use simple cycle like: while true ; do check file ; sleep 2 ; done


20

I might be misunderstanding the question, but is there a reason you can't use this? tail -f /location/of/thefile | grep -i -E "foo|bar"


18

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


17

The difference may be seen via strace: $ strace -ff -o bq watch sh -c 'ls\ /tmp/|wc -l' ^C $ strace -ff -o nobq watch sh -c 'ls /tmp/|wc -l' ^C $ grep exec bq* | grep sh bq.29218:execve("/usr/bin/watch", ["watch", "sh", "-c", "ls\\ /tmp/|wc -l"], [/* 54 vars */]) = 0 bq.29219:execve("/bin/sh", ["sh", "-c", "sh -c ls\\ /tmp/|wc -l"], [/* 56 vars */]) = 0 ...


15

How about: ( # In a subshell, for isolation, protecting $! while true; do perform-command & # in the background sleep 10 ; ### If you want to wait for a perform-command ### that happens to run for more than ten seconds, ### uncomment the following line: # wait $! ; ### If you prefer to kill a perform-command ### that ...


13

Simply type: less +F filename This emulates pressing "F" within the editor.


12

watch is in procps, so install 'procps' package.


11

The purpose of watch is to show the results of a command full-screen and update continuously; if you're redirecting the output into a file and backgrounding it there's really no reason to use watch in the first place. If you want to just run a command over and over again with a delay (watch waits two seconds by default), you can use something like this: ...


9

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


9

What platform are you on? On my Linux (Ubuntu 14.10) the man page says: -n, --interval seconds Specify update interval. The command will not allow quicker than 0.1 second interval, in which the smaller values are con‐ verted. I just tested this with a script calling a C-program that prints the timestamp with ...


8

Actually, you're at the limit. The man page does provide a minimal value (at least on my 2009, Linux version). Here it goes: -n, --interval seconds Specify update interval. The command will not allow quicker than 0.1 second interval, in which the smaller values are converted. You can probably check that by using date through watch: $ watch -n0.1 date ...


8

There are two main categories of watch commands (of the ones that are to run commands periodically, watch is not a standard command, there are even systems where watch does something completely different like snooping on another tty line on FreeBSD). One that already passes the concatenation of its arguments with spaces to a shell (it does in effect call sh ...


8

I'm not sure about your motivations, but maybe this would be enough? while true; do sleep 2; cmd >>output.txt; done & Otherwise, please explain why you really need watch.


8

It seems curl does print the progress stats only when stdout is not a terminal. (e.g. curl -I sandbox.dev|cat would give you these results, too) You can disable these, however. From the manpage -s/--silent Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.


8

Depending on your implementation/version of watch, it may not start a shell to interpret a command line, but instead runs a command that takes as argument the arguments it received itself. So, in that case, if you need it to run a shell command line, you need to start a shell explicitly as in: watch sh -c 'find . | wc -l' See also the inotifywait -rm . ...


8

I found this thread titled: Bug#225549: have watch monitor stderr. That thread is from 2008, but it looks like older versions don't support the watching of anything other than STDOUT. So we're limited to just STDOUT. As for visible there is a lot of language in the info watch and man watch that make me think your observation/assumption is correct. excerpt ...


7

You can do something like the following in bash, zsh, or ksh: SECONDS=0 while command do sleep "$((10-(SECONDS%10)))" done Here's what the bash manual says about $SECONDS: $SECONDS Each time this parameter is referenced, the number of seconds since shell invocation is returned. If a value is assigned to $SECONDS, the value returned upon ...


7

You can watch any command so give this a try watch "ps aux | grep python"


6

watch command is included in procps utilities. The smallest value for -n option is 0.1, it's hardcoded in watch source (see line 171 - 172): case 'n': { char *str; interval = strtod(optarg, &str); if (!*optarg || *str) do_usage(); if(interval < 0.1) interval = 0.1; if(interval > ...


6

A better option than providing the password on the command line at all is to make a ~/.my.cnf file with the credentials in it: [client] password=something That way they are also protected against someone looking at the ps output, or your shell history. That said, you can turn off the watch title entirely with the -t or --no-title option, which will: ...


6

Ok, so there are a few issues with your approach. You are exporting a function, which is not portable between shells. watch executes its commands with /bin/sh, which on your system is not bash. And whatever shell it is, it doesn't respect function exports, so you get the error. Secondly, you can change your command to something like watch bash -c 'func1', ...


6

Add -t to your ssh. By default when you pass a command to ssh, it doesnt allocate a TTY on the remote host, so the application only has a basic STDOUT pipe to work with. ssh -t foobar 'watch -t -d -n 1 "netstat -veeantpo | grep 43597"'


5

This is a locale problem. watch uses strtod(3), which is locale-dependent, to convert the argument to -n to a double. To fix the problem, you need to either specify the argument to -n with a different separator: watch -n 0,1 w Or change your locale to a setting where the period character is used for the decimal point: export LC_NUMERIC=en_US.UTF-8 watch ...


4

There exists several variants of a watch command, some that spawn a shell to interpret a command line made of the concatenation of the arguments passed to watch (with space characters in between). In those you can do: watch 'ls | shuf' same as: watch ls '|' shuf (those watch actually run: "/bin/sh", ["sh", "-c", "ls | shuf"] and are quite dangerous in ...


4

In bash, you can do this easily using the PROMPT_COMMAND variable (from man bash): PROMPT_COMMAND If set, the value is executed as a command prior to issuing each primary prompt. So, if you add something like this to your ~/.bashrc: PROMPT_COMMAND=". /path/to/file" You will have any variables defined in that file available.


4

Installed the ncurses package and then I get a clear screen on every run. Thank you rush. I ran mine as while true ; do clear; <command> <file> ; sleep 2 ; done such as while true ; do clear; grep ERROR server.log | tail -n 5 ; done


4

Here's a way: watch -n 1 'date' &>/dev/null & Since you background the process, we can assume you don't need the terminal display and you are fine redirecting to a file. If you do that you will be able to background watch without issue. sleep, as suggested by Michael Mrozek, will slowly lag which can be undesirable. Aside from a convoluted ...


4

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.



Only top voted, non community-wiki answers of a minimum length are eligible