Tag Info

Hot answers tagged

39

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


29

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


26

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


19

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"


17

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


10

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


10

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


8

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


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


8

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


7

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


7

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.


7

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.


7

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


6

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


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


5

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

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


5

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


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.


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

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', ...


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

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


3

Try: watch 'bash -c "diff <(pacman -Q) <(ssh kate \"pacman -Q\")"'


3

Contrast: $ watch -n 1 "echo $(date)" Every 1.0s: echo Sat Apr 27 03:10:50 CEST 2013 $ watch -n 1 'echo $(date)' Every 1.0s: echo $(date) What you've done is to run echo "($ls DirFlat |wc -l)*100/$FileNum"|bc and date, substitute the output of each command into the shell command watch -n 100 "echo $(…) % $(…)", and run that. You need to prevent the ...


3

When git status is run under watch, it is able to detect that its standard output is not a terminal, meaning it will not output colors if the color.status setting is set to auto. To force git status to always output colors (even under watch), set color.stats to always, e.g. git config color.status always to set the setting permanently, or as ...


3

You can use the -t switch to watch which causes it not to print header. However, that will still clear the screen so you might be better off with a simple shell loop: while sleep 1; do wc -l my.log done One of the advantages is, that you can easily add other commands (e.g. date) and/or pipe the output through sed to reformat it. By the way, if you ...


3

It will not only show up on your screen, but also in ps output, in your ~/.bash_history (though that one should only be readable to you and the admins) and possibly in some audit or performance logs. You should not pass passwords as arguments to commands. Arguments to commands should be considered public knowledge. For mysql, use ~/.my.cnf as Michael has ...


3

In your crontab : * * * * * date >> dateFile.txt & sleep 30; date >> dateFile.txt & Straightforward, no ? =) (Better put the full PATH of the date command) Another solution: while true; do date >> dateFile.txt & sleep 30; done



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