simple introduction for redirection

1. standard input and output

        equipment        file name      file descriptor      type

        keyboard           /dev/stdin     0                             standard input

        monitor             /dev/stdout   1                             standard output

        monitor             /dev/stderr    2                             standard err output

2. output redirection

        command > file               cover               standard input to file or equipment

        command >> file             append          standard input to file or equipment

        err command 2> file         cover            standard err input to file or equipment

        err command 2>> file       append       standard err input to file or equipment 

3. output 2 ways at same time

        command > file 2>&1         cover          output 2 ways in same file

        command &> file

        command >> file 2>&1       append      output 2 ways in same file

        command &>> file

        command &>/dev/null            special file, black hole

        command >>file1 2>>file2    output the correct result appending to file1 and the error result appending to file2

4. input redirection

        wc [<] [option] [filename]   count the input strings or file

                -c   count bytes

                -w  count words

                -l    count rows

        wc << [words]                      count the input strings between beginning and the words

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章