Operating system | Unix and Unix-like |
---|---|
Platform | Cross-platform |
Type | Command |
License | coreutils: GPLv3+ |
yes
is a command on Unix and Unix-like operating systems, which outputs an affirmative response, or a user-defined string of text, continuously until killed.
By itself, the yes
command outputs 'y' or whatever is specified as an argument, followed by a newline repeatedly until stopped by the user or otherwise killed; when piped into a command, it will continue until the pipe breaks (i.e., the program completes its execution). However, if the user enters a string after 'yes,' yes will output the string the same as it would 'y,' similar to echo.
The version of yes
bundled in GNU coreutils was written by David MacKenzie. [1]
The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project [2] and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities. [3]
yes
can be used to send an affirmative (or negative; e.g. yes n
) response to any command that would otherwise request one, thereby causing the command to run non-interactively.
Piping yes to a command with many user-confirmation prompts will automatically answer all of those prompts with "yes" (typing 'y' and pressing return).
The following commands
$yes|sudoaptinstallfoobar
will answer the prompts for confirmation with y, effectively installing foobar with sudo apt without any prompts.
This usage may be obsolete today, as most commands that would request response from the user have either a 'force' option (e.g., rm -f
) or an 'assume-yes' option (for example, apt -y
).
As an example, the following:
$rm-f*.txt
is functionally equivalent to
$yes|rm*.txt
The yes
command in conjunction with the head command can be used to generate large volume files for means of testing. For example, executing
$yes1234567|head-n1000>file
results in a file consisting of 1000 lines each consisting of eight characters (1, 2, 3, 4, 5, 6, 7 and newline).
yes
can be used as an easy way of generating CPU load. In 2006, for example, the yes
command received publicity for being a means to test whether or not a user's MacBook is affected by the "Intermittent Shutdown Syndrome" bug, where a MacBook would randomly shut off without any user input. By running the yes
command indefinitely twice via Terminal under Mac OS X, users were able to max out their computer's CPU, and thus see if the failure was heat related. [4] [5]
The implementation of yes
on different Unix and Unix-likes was consistently implemented with a simple while-loop. The GNU Project's implementation of yes
was much faster than any other implementation, achieved by buffering its output, leading to more output per system call. [6] [7] GNU's implementation may have been different to avoid infringing on the Unix copyright. The FreeBSD Project changed their implementation in 2017 to match GNU's implementation. [8]
basename is a standard computer program on Unix and Unix-like operating systems. When basename is given a pathname, it will delete any prefix up to the last slash ('/'
) character and return the result. basename is described in the Single UNIX Specification and is primarily used in shell scripts.
uname is a computer program in Unix and Unix-like computer operating systems that prints the name, version and other details about the current machine and the operating system running on it.
The Unix command su, which stands for 'substitute user', is used by a computer user to execute commands with the privileges of another user account. When executed it invokes a shell without changing the current working directory or the user environment.
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.
tr is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.
wc
is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.
cksum
is a command in Unix and Unix-like operating systems that generates a checksum value for a file or stream of data. The cksum command reads each file given in its arguments, or standard input if no arguments are provided, and outputs the file's 32-bit cyclic redundancy check (CRC) checksum and byte count. The CRC output by cksum is different from the CRC-32 used in zip, PNG and zlib.
df is a standard Unix command used to display the amount of available disk space for file systems on which the invoking user has appropriate read access. df is typically implemented using the statfs or statvfs system calls.
paste is a Unix command line utility which is used to join files horizontally by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output.
nl is a Unix utility for numbering lines, either from a file or from standard input, reproducing output on standard output.
mv
is a Unix command that moves one or more files or directories from one place to another. If both filenames are on the same filesystem, this results in a simple file rename; otherwise the file content is copied to the new location and the old file is removed. Using mv
requires the user to have write permission for the directories the file will move between. This is because mv
changes the content of both directories involved in the move. When using the mv
command on files located on the same filesystem, the file's timestamp is not updated.
rm
is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del
command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.
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 computing, whoami is a command found on most Unix-like operating systems, Intel iRMX 86, every Microsoft Windows operating system since Windows Server 2003, and on ReactOS. It is a concatenation of the words "Who am I?" and prints the effective username of the current user when invoked.
sum is a legacy utility available on some Unix and Unix-like operating systems. This utility outputs a 16-bit checksum of each argument file, as well as the number of blocks they take on disk. Two different checksum algorithms are in use. POSIX abandoned sum
in favor of cksum.
In Unix and Unix-like operating systems, printf is a shell builtin that formats and outputs text like the same-named C function.
The csplit
command in Unix and Unix-like operating systems is a utility that is used to split a file into two or more smaller files determined by context lines.
fold is a Unix command used for making a file with long lines more readable on a limited width computer terminal by performing a line wrap.
On Unix-like computer systems, seq is a utility for generating a sequence of numbers.
yes
(GNU version)