File Descriptor : in linux, "everything is a file" and file has a number called file descriptor. file descriptor allow system to access file easily. see following table.
Redirection : redirection allow to change standard input or output of command. following are redirection types.
Input Redirection : In input redirection input(standard input) is passed to command or program using <
symbol. see following example, in
cat < abc.txt command shell open file and
write content to the standard input of another process(here cat command). ie we are passing abc.txt as
input to cat command.
Output Redirection : In output redirection output(except standard error) of command or file or program
is redirected or passed as input to file or program instead of printing on terminal. to do this >
symbol is used. see following example 2,
find command will find file that has
extension .js. output of find command shows some standard error as ": Permission denied". then we execute
find command with > f.txt. this will store output except standard errors in f.txt and print
standard errors on terminal. at the end we print f.txt file on terminal.
Note : when we store output in file if file is already created it will override that file. so select file name correctly.
if you want to append output to file instead of creating file use >> instead of >
find . -name "*.js" >> output.txt
Error Redirection : in error redirection error is redirected from terminal. following are ways to redirect error.
findcommand will find file that has extension .js. output of find command shows some standard error as ": Permission denied". then we execute find command with 2>output1.txt. here 2 is standard error(file descriptor). 2>output1.txt will send only standard error of output to output1.txt file and print remaining output(excluding standard errors) on terminal. at the end we print output1.txt file that contains standard errors of find command.