CentOS Linux Server Guide

Centos Linux Command Line Operation

File Redirection

 

There are 3 types of standard out and output in Linux

 
Type Definition
Stdin Standard Input, which default is keyboard
Stdout Standard Ouput, which default is screen
Stderr Standard Error Output, which default is screen

 

You have an option to redirect the above standard input and output to by appling the following symbols

 
Symbols Definition
> This will redirect the stdout output to another input location such as file.

Note: When you apply > to a file, the previous content of the file will be overwrritten!

echo "abc" > test.txt

cat test.txt
abc

echo "123" > test.txt

cat test.txt
123

 

 

>> This will redirect the stdout output and appended to another input location such as file.
echo "456" >> test.txt
 

cat test.txt
123
456

 

 

2> This will redirect both standard output and error output to another input location such as file.

The following example shows the error message was directed to error.txt.

find /etc/sysconfig/network Micheal &> error.txt
 

ls -l
total 44
drwxr-xr-x 2 root root 4096 Nov 29 17:19 Dir_empty
-rw-r--r-- 1 root root 64 Nov 30 01:22 error.txt
-rw-r----- 1 root root 0 Nov 30 00:10 jane
drwxr-xr-x 2 root root 4096 Nov 28 16:00 myDir
drwxr-xr-x 2 root root 4096 Nov 28 15:43 newmyDir
-rw-r--r-- 1 root root 8 Nov 30 00:59 test.txt
[root@srv1 demo]# cat error.txt
/etc/sysconfig/network
find: Micheal: No such file or directory

 

 

 

Back to Command Line Operation



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy