diff --git a/Operating_Systems/Devices.md b/Operating_Systems/Devices.md index d28a4e1..150c4fb 100644 --- a/Operating_Systems/Devices.md +++ b/Operating_Systems/Devices.md @@ -47,6 +47,6 @@ The [mode](/Programming_Languages/Shell_Scripting/File_permissions_and_execution ## /dev/null -`/dev/null` is a virtual device: it doesn't actually exist as a piece of hardware on the system. +`/dev/null` is a virtual device: it doesn't actually exist as a piece of hardware on the system. It can be useful when [bash scripting](/Programming_Languages/Shell/Redirect_to_dev_null.md) as a place to direct output that you don't care about, for example errors or verbose program read-outs. > ! Make notes on this. Base on : https://linuxhint.com/what_is_dev_null/ diff --git a/Programming_Languages/Shell/Redirect_to_dev_null.md b/Programming_Languages/Shell/Redirect_to_dev_null.md new file mode 100644 index 0000000..5d374e1 --- /dev/null +++ b/Programming_Languages/Shell/Redirect_to_dev_null.md @@ -0,0 +1,29 @@ +--- +categories: + - Programming Languages +tags: + - shell +--- + +# Redirecting to `/dev/null` + +You'll see the following a lot when reading shell scripts: + +```bash +[some_command] > /dev/null 2>&1 + +``` + +This is a redirection statement. It is redirecting data to the `null` device on Unix systems. Basically to a black hole or shredder where you can't access it because you don't want it to be output to stout. + +The `2>&1` argument is the content: any errors that the program may generate and try to show in stout. + +## Example + +I have used this in my Mongo start-up script: + +``` +mongodb-compass > /dev/null 2>&1 +``` + +Here, I just want the MongoDB Compass application to start, I don't care if it wants to output complaints to the stout.