Standard Input, Output and Error in linux

Standard Input, Output and Error in linux

In this post i am going to explain about standard Input, Output and Error in linux. Basically linux provides three I/O channel they are given below

1.Standard Input – Standard Input is coming from Keyboard by default
2.Standard Output – Standard Output is going to screen by default
3.Standard Error – Standard Error is going to screen by default

 

Standard Input, Output and Error

 

If you execute the below command as a local user you may get some standard error and it will be displayed in the screen.

[rajkumar@client ~] find /etc -name passwd
find: /etc/selinux/strict/modules/active: Permission denied
find: /etc/selinux/strict/modules/previous: Permission denied
find: /etc/selinux/targeted/modules/active: Permission denied
find: /etc/selinux/targeted/modules/previous: Permission denied
find: /etc/selinux/mls/modules/active: Permission denied
find: /etc/selinux/mls/modules/previous: Permission denied
find: /etc/audit: Permission denied
/etc/passwd
find: /etc/pki/CA: Permission denied
find: /etc/racoon/certs: Permission denied
find: /etc/Pegasus: Permission denied
/etc/pam.d/passwd
find: /etc/quagga: Permission denied
find: /etc/lvm/backup: Permission denied
find: /etc/lvm/cache: Permission denied
find: /etc/lvm/archive: Permission denied
find: /etc/cron.d: Permission denied
find: /etc/cups/ssl: Permission denied
/etc/uucp/passwd

Standard Input, Output and Error

Redirecting Standard output to a file

To redirect standard output to a file use “>” operator

Syntax:

#Command > filename

Example:

# find /etc -name passwd > ~/pass

Standard Input, Output and Error

 

In the above example i have redirected the standard output of the command “find /etc -name” to a file “~/pass” using operator “>”

Redirecting Standard Error to a file

To redirect Standard Error to a file use “2>” Option

Example:

#find /etc -name passwd 2> ~/error_file

Standard Input, Output and Error

In the above example i have redirected the standard error of the command “find /etc -name passwd” to a file “~/error_file” using “2>” operator

Redirecting Standard Output and Error to file

To redirect both standard output and standard error to a file use “&>” operator

Example:

#find /etc -name passwd &> ~/total_output

Standard Input, Output and Error

In the above example i have redirected both output and error to a single file “~/total_output” using the option “&>” .




Leave a Reply

Your email address will not be published. Required fields are marked *