Skip to Content
Shell Scripting: Expert Recipes for Linux, Bash, and More
book

Shell Scripting: Expert Recipes for Linux, Bash, and More

by Steve Parker
August 2011
Beginner to intermediate
600 pages
14h 29m
English
Wrox
Content preview from Shell Scripting: Expert Recipes for Linux, Bash, and More

yes

A lot of utilities, such as fsck, have a -y option to say “yes” to all questions that they may ask. The good ones are then written so that “yes” to any question means basically the same thing — whether it’s to mark superblocks clean or to remove inodes, the -y flag to fsck indicates that it should do whatever is necessary to fix the filesystem. This can be very useful for scripts as it means that they do not have to interact with the user. Some tools do not have this option, and yes can be useful when using these interactively. What yes does is spew out a continuous supply of the letter y. These two commands are equivalent:

# fsck -y /dev/sdf1
# yes | fsck /dev/sdf1
note.ai

As an alternative, yes can take any other text as a parameter, and it will display that instead.

One use for yes that may not look too obvious at first glance is this one-line command:

yes no | cp -i * /tmp

This pipes the word “no” into the cp command, which, when called as cp -i, will always query before overwriting a file. The net result of this is that existing files will not be replaced, but other files will be copied into /tmp. Not often required, but it is at least entertaining for the way it looks as well as being occasionally useful, too.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Command Line and Shell Scripting Techniques

Linux Command Line and Shell Scripting Techniques

Vedran Dakic, Jasmin Redzepagic
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781118166321Purchase bookDownloads