Watch (command)

Last updated
watch
Original author(s) Tony Rems
Developer(s) Francois Pinard,
Mike Coleman,
Albert Cahalan,
Morty Abzug,
Jarrod Lowe
Initial release1991;30 years ago (1991)
Repository gitlab.com/procps-ng/procps
Operating system Unix-like
Type Command
License GPLv2.1+

watch is a command-line tool, part of the Linux procps and procps-ng packages, that runs the specified command repeatedly and displays the results on standard output so the user can watch it change over time. By default, the command is run every two seconds, although this is adjustable with the -n secs argument. Since the command is passed to sh -c, it may be necessary to encase it in quotes for it to run correctly.

Contents

Syntax

watch [options] command [command options]

Example

watch "ps -e | grep php"

This will generate a list of processes every two seconds, filter for all lines that contain the word "php", and display the results on the screen. The output might look something like this:

Every 2s: ps -e | grep php                             Tue Jan 30 14:56:33 2007  reconst  30028  0.0  0.0  7044 2596 ?        S    Jan23   0:00 vim -r core/html_api.php cinonet  28009  0.0  0.2 20708 11064 ?       SN   Jan25   0:30 php5.cgi donoiz   23810  0.0  0.2 22740 10996 ?       SN   Jan27   0:30 php.cgi 43/pdf

The watch command is useful for viewing changes over time, like repeatedly running the ls -l command to watch a file's size change, or running ps as in the above example to monitor certain processes continuously.

Arguments

See also

Related Research Articles

Bash (Unix shell) GNU replacement for the Bourne shell

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used as the default login shell for most Linux distributions. A version is also available for Windows 10 via the Windows Subsystem for Linux. It is also the default user shell in Solaris 11. Bash was also the default shell in all versions of Apple macOS prior to the 2019 release of macOS Catalina, which changed the default shell to zsh, although Bash currently remains available as an alternative shell.

In computing, Common Gateway Interface (CGI) is an interface specification that enables web servers to execute an external program, typically to process user requests.

ls

In computing, ls is a command to list computer files in Unix and Unix-like operating systems. ls is specified by POSIX and the Single UNIX Specification. When invoked without any arguments, ls lists the files in the current working directory. The command is also available in the EFI shell. In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the dir command. The numerical computing environments MATLAB and GNU Octave include an ls function with similar functionality.

xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.

cURL is a computer software project providing a library (libcurl) and command-line tool (curl) for transferring data using various network protocols. The name stands for "Client URL", which was first released in 1996.

dd is a command-line utility for Unix and Unix-like operating systems, the primary purpose of which is to convert and copy files.

top (software) Task manager program found in many Unix-like operating systems

top is a task manager program, found in many Unix-like operating systems, that displays information about CPU and memory utilization.

ps (Unix) Standard UNIX utility that displays the currently-running processes

In most Unix and Unix-like operating systems, the ps program displays the currently-running processes. A related Unix utility named top provides a real-time view of the running processes.

netstat Command line network statistics tool

In computing, netstat is a command-line network utility that displays network connections for Transmission Control Protocol, routing tables, and a number of network interface and network protocol statistics. It is available on Unix, Plan 9, Inferno, and Unix-like operating systems including macOS, Linux, Solaris and BSD. It is also available on IBM OS/2 and on Microsoft Windows NT-based operating systems including Windows XP, Windows Vista, Windows 7, Windows 8 and Windows 10.

who (Unix)

The standard Unix command who displays a list of users who are currently logged into the computer.

more (command)

In computing, more is a command to view the contents of a text file one screen at a time. It is available on Unix and Unix-like systems, DOS, Digital Research FlexOS, IBM/Toshiba 4690 OS, IBM OS/2, Microsoft Windows and ReactOS. Programs of this sort are called pagers. more is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.

tail is a program available on Unix, Unix-like systems, FreeDOS and MSX-DOS used to display the tail end of a text file or piped data.

In computing, tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.

In Unix and Unix-like operating systems, job control refers to control of jobs by a shell, especially interactively, where a "job" is a shell's representation for a process group. Basic job control features are the suspending, resuming, or terminating of all processes in the job/process group; more advanced features can be performed by sending signals to the job. Job control is of particular interest in Unix due to its multiprocessing, and should be distinguished from job control generally, which is frequently applied to sequential execution.

pgrep is a command-line utility initially written for use with the Solaris 7 operating system by Mike Shapiro. It has since been available in illumos and reimplemented for the Linux and BSDs. It searches for all the named processes that can be specified as extended regular expression patterns, and—by default—returns their process ID. Alternatives include pidof and ps.

Toybox is a free and open-source software implementation of over 200 Unix command line utilities such as ls, cp, and mv. The Toybox project was started in 2006, and became a 0BSD licensed BusyBox alternative. Toybox is used for most of Android's command line tools in all currently supported Android versions, and is also used to build Android on Linux and macOS. All of the tools are tested on Linux, and many of them also work on BSD and macOS.

On Apple computers, pmset is a command line utility to manipulate power management settings under the Darwin and macOS operating systems. It can assign sleep settings, schedule sleep and wake times, and display power information.

ngrep

ngrep is a network packet analyzer written by Jordan Ritter. It has a command-line interface, and relies upon the pcap library and the GNU regex library.

Command-line interface Type of computer interface based on entering text commands and viewing text output

A command-line interface (CLI) processes commands to a computer program in the form of lines of text. The program which handles the interface is called a command-line interpreter or command-line processor. Operating systems implement a command-line interface in a shell for interactive access to operating system functions or services. Such access was primarily provided to users by computer terminals starting in the mid-1960s, and continued to be used throughout the 1970s and 1980s on VAX/VMS, Unix systems and personal computer systems including DOS, CP/M and Apple DOS.

cat (Unix)

cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to concatenate files. It was ported to a number of operating systems.