Ever have a command you run in Linux that ends up asking you the same question over and over again? Isn’t it annoying how you have to type the same thing in over and over again. I’m specifically referring to if you have a folder with a bunch of files that you’re trying to remove. So of course you say:
rm -r <direcotory>
cd <direcotory> rm *
Either way you do it, you might end up with an “Are you sure” for ever file. I know it happens sometimes for me when I’m deleting files as root that are owned by another user – which I don’t do very often, but do do every once in a while. Pragmatists will tell you to use the -f (force) parameter
rm -rf <directory>
cd <directory> rm -f *
But the purists will tell you that that’s bad bad bad. Or maybe you’re a pragmatist and whatever command you’re using doesn’t have a force parameter. Then let me introduce you to “yes”. That’s right, folks. Try it out. Open terminal and type:
Magic! The screen repeated echos y on a new line until you press CTRL+C. Moreover, if you pass it a parameter, it will echo the parameter you pass until you press CTRL+C.
Print ‘n’ instead of ‘y’. So for our above scenario, let’s say we want to remove a bunch of files and say yes to all the confirmation prompts, but don’t want to use -f and don’t want to type y over and over again. Our solution is simple:
yes | rm -r <directory>
cd <directory> yes | rm *
Neat trick! I’m sure it has other uses too, and I’m sure a quick perusal of “man yes” will reveal other ways to customize it.