There are three directions on the command line..
Let's pretend we have some java program that reads in some words, then outputs them. We can run this program by typing the words ourselves (as arguments). Or we can redirect a file to be the standard input.
$ java test < testInput.txt
This would send the the text in helloWorld.txt as the inputs.
When running a program or command, the normal output will appear on the terminal - this is known as the standard out.
To redirect standard out to a file, we use >. So instead of outputting our standard out to the screen, it will store it in a file called lsTestOutput.txt. In case we don't want to overwrite the existing contents of lsTestOutput.txt, we can use >> instead of >.
$ ls -l > lsTestOutput.txt
To redirect standard error, we use 2>
$ java notARealProgram 2> errorMessage.txt
Since notARealProgram isn't a real program in our case, this will result in an error that gets directed to errorMessage.txt.
To redirect both standard error and standard out together, use &>.
You can use both standard in and out notations in case you need to input some arguments, and would like to output to a file.
$ java test < inputFile.txt > outputFile.txt
To specify one file as both the standard input and output, use
$ java test < inAndOutFile.txt
/dev/null is a special folder that acts like a trash bin (nothing gets saved there).
If you want to suppress error messages, you can direct your standard error to /dev/null.
$ java notARealProgram 2> /dev/null
Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.$ Check price
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