Table of contents
No headings in the article.
In Linux, there are three standard streams; standard input ( stdin ), standard output ( stdout ), and standard error ( stderr ). Each stream is represented by a file descriptor. The standard input is represented by a 0 , the standard output by a 1 , and the standard error by a 2.
Stdout(Standard Output)
Now suppose I have a directory named "project1" having a.txt , b.txt, c.txt and "project2" having d.txt , e.txt , f.txt , g.txt respectively. Now I want to store the output received by$ ls project1
into an output.txt file via command $ ls > ~/output.txt
, will look something like this :
Now if we do $ ls project2
, and store it's output in the same output.txt file with command $ ls > output.txt
, it will store the new output. Rather than rewriting even the previous outputs , it will write the new ones.
But we want everything to be written i.e the output of project1 as well as of project2, just do $ ls >> ~/output.txt
Stderr(Standard error)
Since we have storedls
command's output in "output.txt" . But lets do $ lg > output.txt
, as we know this is a wrong command , but an empty output.txt would be created.
But what if we want to store the error also. Command for that is $ lg 2> output.txt
What if we want to nullify the error we are receiving upon doing lg
rather than ls
command , that can be done using $ lg 2> /dev/null
command.
Suppose we do $ ls -la /etc
command , we get a lot of information about the "/etc" folder and it messes up our terminal. To deal with this , we have $ less
command and press "q" to exit that mode.
"Pipe" : Here the output of the first command becomes the input for the second
ex: $ ls -la /etc | less
and then press "q".
Environment Variables
The environment variables are dynamic values that are stored within a system and used by applications launched in shells or sub-shells. These variables have a name and their respected value. The environment variable customizes the system performance and the behavior of an application.
$ echo $PATH
: contains all the paths that a system will search whenever we execute a command.
$ head: command prints first 10 lines of any file.
$ tail : command prints the last 10 lines of any file.
$ sort : arrange the file according to the letters.
$ uniq : display all singly repeated values inside a file.
$ grep : “global regular expression print”, is a command used in searching and matching text files contained in the regular expressions. Furthermore, the command comes pre-installed in every Linux.
That's all for this one , share it with your friends and like it. In the next one we will go through the "Linux System administration and the Permissions ". Thanks once again everyone.
Do connect with me on Twitter :)