The idea behind a standard input and output is that there is a data source, a sink and a place to report all errors.
To summarize standard IO:
As an example, take this RepeatInput program which reads in an input, then spits it back out.
$ java RepeatInput < "hello world!" > hello_world.txt # "hello world!" now stored in hello_world.txt
/dev/null is a special place on our UNIX machine that acts as a trash bin. Anything sent to /dev/null is discarded.
If you want to omit all errors when running a program (which you should have a very good reason to do) then you can simply direct error messages to /dev/null.
#!/bin/bash # Program runs silently by throwing away error messages java ProgramWithErrors 2> /dev/null
You can also run a script that clears files by overwriting its content with /dev/null
#!/bin/bash cd /var/log cat /dev/null > logMessages echo "Log files all cleaned up!"
There are also pipelines, which are used to take the standard output of one command to be used as the standard input of another command. These commands are joined together by a
Pipelines should be ordered so that you reduce the most amount of data on each step.
$ ls | grep .txt | wc -w # How many files with .txt extension are in current folder 22
The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.$ Check price
Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.$ Check price