We have moved to www.dataGenX.net, Keep Learning with us.

Thursday, September 25, 2014

File descripters in Unix

A file descriptor is an abstract value of type Unix.file_descr, containing information necessary to use a file: a pointer to the file, the access rights, the access modes (read or write), the current position in the file
or we can say
Under the covers of the Unix operating system, files are referenced, copied, and moved by unique numbers known as file descriptors.

Three descriptors are predefined. They correspond to standard input, standard output, and standard error.

0 - stdin (Standard Input)  "<"
1 - stdout ( Standard Output) "1>" or ">"
2 - stderr ( Standard Error) "2>"

i.e -

$ echo "This is a Command" >output.txt 2>error.txt
$ echo "This is a Command" 1>output.txt 2>error.txt
$ echo "This is a Command" 2>error.txt 1>output.txt 

both command will work same. 1> or > is for Output. Here the output of the command is stored in the file "output.txt" and if any error occur in command it will be store in "error.txt" file

Some Imp Example :-

a) For creating a new blank file
            $  >filename

b) What will this command output ?
            $ cat filename 

            $ cat filename > filename 

Like the Facebook Page & join Group

For WHATSAPP group , drop a msg to 91-88-00-906098