Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now that we've talked about the basics of redirecting input and output, there is one last redirection technique that you should know about. Instead of redirecting output to a file or into a command, what if we want to have no output at all? This is especially useful when you become advanced enough that you're able to setup scripts on a server that run automatically at 4 a.m. even when there's not anyone logged in to view the output. At that point you don't need the output, right. You just want it to just do this thing and the output should just go away, and there may also be occasions where you want to run a program or you just don't want to see the output. You just want the program to do its thing and get its results.
Well we could just put the output to a file and then throw away the file, but there is an even easier way to do it. We can redirect the output to a special file that referred to as the null device. It's also sometimes called the bit bucket or the black hole, and it lives at /dev/null. Do you remember I told you that there were the special files for input and output that were represented at dev /standard in and dev/standard out? Well, dev/null is another one that's in that same folder. It's a special device where anything that's directed there Unix just discards.
It just like a black hole. We just send data there and Unix says "Oh, yeah okay, never mind." It's gone. It's not kept in memory. It's not kept in the file. It just disappears. And the way you send things to dev/null is the same way that you send them to any file. So for example let's just take a simple listing right, ls -la. Let's send that to dev/null, always at the root, all right,. Always we have to make sure we specify that so it knows the absolute path dev/null. We get no output. cat lorem_ipsum, let's send that to dev/ null. All right, there is nothing there.
If we want to bring in nothing, let's bring in nothing from dev/null, all right. It echoes back nothing to us. So it works just like a file. It's just like a special file, but it has this unique property of always staying empty. Now in truth you may not have need for this very often but it is an important concept I think for you to know, and so I want you to recognize it whenever you come across it in your future Unix endeavors, so that you know how you can have something that has absolutely no output. The way you suppress output is you direct the output to dev/null.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.