| |||||||||||||||||||||||||||||||||||||
| Home > Tech Notes > Operating System > Linux > Linux Basic (User Level) | |||||||||||||||||||||||||||||||||||||
| 1 Linux Basic | |||||||||||||||||||||||||||||||||||||
| Understanding Linux Basic | |||||||||||||||||||||||||||||||||||||
| Shell Commands | |||||||||||||||||||||||||||||||||||||
| Standard I/O, Redirection, Pipe & tee | |||||||||||||||||||||||||||||||||||||
Linux commands communicate via the CLI. It can print information out to the terminal, and accept input from the keyboard. It has 3 streams (connections) to the outside world viz. input, output & error. Standard Input : Mainly Keyboard Input, but redirection of one command output to another command; reading from file can also be called Standard I/O Standard Output : Mainly Terminal Window, but redirection to file can also be called Standard I/O Standard Error : Initially attached to the command window, but it has separate channel intended for printing error messages. You can attach one or more of these three streams to a file, a device, or even to another program. | |||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||
| The wc program counts lines, characters and words in data sent to its standard input. You can use it interactively like this. e.g. This is a perfect example of Standard Input | |||||||||||||||||||||||||||||||||||||
| [gauri@localhost linux]$ wc This is test for standard I/O wc means word count. wc will count lines, words & characters too. Press Ctrl + d ( ^D) to complete writing This is last line ^D 6 31 157 [gauri@localhost linux]$ | |||||||||||||||||||||||||||||||||||||
| prog < input > output e.g. Here you are reading myFile.txt. Input to cat command is give by < & output is stored to newFile.txt with redirection ">". | |||||||||||||||||||||||||||||||||||||
| [gauri@localhost linux]$ cat < myFile.txt > newFile.txt | |||||||||||||||||||||||||||||||||||||
| prog < input > output 2> errors e.g. Here you are reading myFile.txt. Input to cat command is give by <, output is stored to newFile.txt with redirection ">" & error (if there is any) will be redirected to new file. This is applicable on bash shell. | |||||||||||||||||||||||||||||||||||||
| [gauri@localhost linux]$ cat < myFile.txt > newFile.txt 2> error.txt | |||||||||||||||||||||||||||||||||||||
| prog < input > output 2> errors e.g. Here you are reading myFile.txt. Input to cat command is give by <, output is stored to newFile.txt with redirection ">" & error (if there is any) will be redirected to new file. This is applicable on c shell. | |||||||||||||||||||||||||||||||||||||
| [gauri@localhost linux]% cat < myFile.txt > newFile.txt >& error.txt | |||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||