Open In App

yes command in Linux with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

yes, the command in Linux is used to print a continuous output stream of a given STRING. If STRING is not mentioned then it prints ‘y’;

Syntax: of `yes` command in Linux

yes [STRING]

Note: To stop printing please press Ctrl + C.

Use of `yes` command

let us say that we want to delete all the `.txt` files present in the current directory. Instead of writing `rm -i *.txt` and then typing y at the end for every file, what can be we can use `yes | rm -i *.txt`.

Creating Dummy Files

We can use `yes` command to generate a dummy file quickly by redirecting its output to a file, we can create a file with repetitive content.

For Example:

If we want to create a file name `jayesh.txt` with 100 lines containing “hello GFG”.

Syntax:

yes "Hello GFG" | head -n 100 > jayesh.txt

We used `cat jayesh.txt` to see the content in the file

387

In this example, “yes” generates an infinite stream of “Hello World” strings, which is then piped to the “head” command to limit the output to 100 lines. Finally, the content is redirected to the “dummy.txt” file.

Options:

  • yes –help : It displays help information.

  • yes –version : It displays version information.


Last Updated : 31 Jul, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads