1. 标准输入和输出

    提供三个通道

    clip_p_w_picpath001 0标准输入Keybord is default

    clip_p_w_picpath001[1] 1标准输出Terminal windows is default

    clip_p_w_picpath001[2] 2标准错误Terminal windows is default

    [root@localhost root]# ls -l /dev/std*

    lrwxrwxrwx 1 root root 17 2008-10-02 /dev/stderr -> ../proc/self/fd/2

    lrwxrwxrwx 1 root root 17 2008-10-02 /dev/stdin -> ../proc/self/fd/0

    lrwxrwxrwx 1 root root 17 2008-10-02 /dev/stdout -> ../proc/self/fd/1

    [root@localhost root]#

  2. 将输出的咨询显示在终端上Redirecting out displayed on the terminal

    标准输出信息

    [root@localhost root]# ls -l

    总用量 36

    -rw-r--r-- 1 root root 1215 2008-10-02 anaconda-ks.cfg

    drwxr-xr-x 2 root root 4096 7月 24 13:57 doc

    -rw-r--r-- 1 root root 0 7月 24 13:50 funny.txt

    -rw-r--r-- 1 root root 18275 2008-10-02 install.log

    -rw-r--r-- 1 root root 2783 2008-10-02 install.log.syslog

    drwxr-xr-x 2 root root 4096 7月 26 22:54 tmp

     

    标准错误信息

    [root@localhost root]# ls -l abc

    ls: abc: 没有那个文件或目录

    [root@localhost root]# find /etc -name passwd

    /etc/passwd

    /etc/pam.d/passwd

    [root@localhost root]# su - lu

    [lu@localhost lu]$ find /etc -name passwd

    /etc/passwd

    find: /etc/default: 权限不够

    /etc/pam.d/passwd

    find: /etc/cups/certs: 权限不够

    find: /etc/gconf/gconf.xml.defaults/schemas/apps/memprof: 权限不够

    find: /etc/gconf/gconf.xml.defaults/apps/memprof: 权限不够

  3. 将资料导出的方法

    >导出 overite

    >>导出 appending

    <导入

    [root@localhost root]# cal > cal.1

    [root@localhost root]# cat cal.1

    七月 2010

    日 一 二 三 四 五 六

    1 2 3

    4 5 6 7 8 9 10

    11 12 13 14 15 16 17

    18 19 20 21 22 23 24

    25 26 27 28 29 30 31

  4. 将标准信息导出到档案里

    [lu@localhost lu]$ find /etc -name passwd &gt; stdout //默认使用1,标准输出

    find: /etc/default: 权限不够

    find: /etc/cups/certs: 权限不够

    find: /etc/gconf/gconf.xml.defaults/schemas/apps/memprof: 权限不够

    find: /etc/gconf/gconf.xml.defaults/apps/memprof: 权限不够

    [lu@localhost lu]$ cat stdout

    /etc/passwd

    /etc/pam.d/passwd

    [lu@localhost lu]$ find /etc -name passwd 2&gt; stdout //指定使用2,标准错误信息

    /etc/passwd

    /etc/pam.d/passwd

    [lu@localhost lu]$ cat stdout

    find: /etc/default: 权限不够

    find: /etc/cups/certs: 权限不够

    find: /etc/gconf/gconf.xml.defaults/schemas/apps/memprof: 权限不够

    find: /etc/gconf/gconf.xml.defaults/apps/memprof: 权限不够

  5. 将标准错误信息导出到档案

    使用代码2

    [lu@localhost lu]$ find /etc -name passwd 2&gt; stdout

  6. 将标准输出信息和错误信息一次导出到档案

    Find /etc –name passwd 2&gt; errs 1&gt; output

    导出到两个文件

    导出到一个文件

    [lu@localhost lu]$ find /etc -name passwd &gt; alloutput2 2&gt;&1 //指定输出1、2的内容

    [lu@localhost lu]$ cat alloutput2

    /etc/passwd

    find: /etc/default: 权限不够

    /etc/pam.d/passwd

    find: /etc/cups/certs: 权限不够

    find: /etc/gconf/gconf.xml.defaults/schemas/apps/memprof: 权限不够

    find: /etc/gconf/gconf.xml.defaults/apps/memprof: 权限不够

    [lu@localhost lu]$

  7. 将标准输入信息导入

    每个用户目录下均有.bash_profile这个文件

    [lu@localhost lu]$ cat .bash_profile

    # .bash_profile

    # Get the aliases and functions

    if [ -f ~/.bashrc ]; then

    . ~/.bashrc

    fi

    # User specific environment and startup programs

    PATH=$PATH:$HOME/bin

    export PATH

    unset USERNAME

    [lu@localhost lu]$ tr 'A-Z' 'a-z' &lt; .bash_profile //将.bash_profile文件中的内容导入,将大写字符转换为小写字符。

    # .bash_profile

    # get the aliases and functions

    if [ -f ~/.bashrc ]; then

    . ~/.bashrc

    fi

    # user specific environment and startup programs

    path=$path:$home/bin

    export path

    unset username

    [lu@localhost lu]$

  8. 使用cut

    显示档案里特定栏位内容

    -f,

    Cut –f3 cut.tab,显示cut.tab这个文件里第三栏信息

    -d:,使用冒号来区分栏位,默认为tab

    -d,,使用逗号区分

    Cut –f2 –d, cut.csv,显示cut.csv这个文件的第二栏信息,栏目分割使用逗号。

    -c,

    Cut –c4-8 cut.csv,显示第四到第八个字符。

  9. 使用sort

    将输出资料排列

    Sort[option]files

    [lu@localhost lu]$ cat sort-test.txt

    D

    A

    B

    D

    H

    E

    Y

    U

    I

    V

    N

    [lu@localhost lu]$ sort sort-test.txt //按顺序排序

    A

    B

    D

    D

    E

    H

    I

    N

    U

    V

    Y

    [lu@localhost lu]$

    Sort –r,反向排列

    Sort –f,不区分大小写

    Sort –u,唯一性,取出相同的字符

    Sort –t,设定栏位标识符

    Sort –t: -k3 /etc/passwd,使用第三列做为排列,使用冒号作为分隔符。默认以字串作为排列,可以用-n参数。

    [lu@localhost lu]$ sort -t: -k3 /etc/passwd

    root:x:0:0:root:/root:/bin/bash

    uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

    operator:x:11:0:operator:/root:/sbin/nologin

    Sort –n,变成用数值作为排列

    [lu@localhost lu]$ sort -t: -k3 -n /etc/passwd

    root:x:0:0:root:/root:/bin/bash

    bin:x:1:1:bin:/bin:/sbin/nologin

    daemon:x:2:2:daemon:/sbin:/sbin/nologin

    Sort –k,可以设定按照哪一栏作为排列

  10. 使用pipes

    [lu@localhost lu]$ ls -l /etc | less //以less指令输出,即一页一页输出。

    [lu@localhost lu]$ cut -f1 -d: /etc/passwd | sort -r | less //输出第一栏,使用冒号作为分隔符,反向排列,less方式

    xfs

    vcsa

    uucp

    test-user

  11. 又加重使用pipes

    [lu@localhost lu]$ mail -s "lst mail" xxyy@163.com

    hello ,this is a test mail for you

    goodby

    .//结束按.

    Cc:

    [lu@localhost lu]$

    Mail –s “2nd mail” user2 &lt; test.mail

    将test.mail的内容发给user2

    读取指定用户收件夹邮件和内容

    cat /var/spool/mail/root

    输入mail,再输入序号,查看指定邮件内容。

    & q//使用q离开后,会将阅读过的邮件放入回收站

    Saved 2 messages in mbox

    Held 1 message in /var/spool/mail/root