19.wc:外部命令

  功能:显示每个文件中的新行、字和字节数

  格式:wc [OPTION]... [FILE]...

  常用选项:

   -l:来只计数行数

   -w:来只计数单词总数

   -c:来只计数字节总数

   -m:来只计数字符总数

  退出状态:

    如果命令执行成功,状态返回值为0;如果命令执行失败,状态返回值为非0。

  使用举例:

    [root@localhost ~]# cat test     
    this is a testfile
    in linux 
    centos 6.7 release
    [root@localhost ~]# wc < test
     3 10 49
    [root@localhost ~]# wc test
     3 10 49 test
    [root@localhost ~]# wc -l test
    3 test
    [root@localhost ~]#


20.file:外部命令

  功能:判定文件类型

  格式:

    file [-bchiklLNnprsvz0] [--apple] [--mime-encoding] [--mime-type] [-e testname] [-F separator][-f namefile] [-m magicfiles] file ...

    file -C [-m magicfiles]

    file [--help]

  常用选项:

    -b, --brief:在输出信息的时候不考虑文件名        

  退出状态:

    如果命令执行成功,状态返回值为0;如果命令执行失败,状态返回值为非0。

  使用举例:

    [root@localhost ~]# file  /etc    
    /etc: directory
    [root@localhost ~]# file -b /etc
    directory
    [root@localhost ~]#


21.tr:外部命令

  功能:转换和删除字符

  格式:tr [OPTION]... SET1 [SET2]

  常用选项:

    -c, -C, --complement:使用SET1集合的补充字符

    -d, --delete:删除SET1中的字符,不实施转换

    -s, --squeeze-repeats:将SET1中列出的字符去重(如果重复,只显示一个)

   还有几个常用的特殊的转义序列:

      \n:换行

      \r:回车(多见于Windows中记事本编辑的文档)

  退出状态:

    如果命令执行成功,状态返回值为0;如果命令执行失败,状态返回值为非0。

  使用举例:

    [root@localhost test]# wc < windows.txt     
     4 18 77
    [root@localhost test]# cat -A windows.txt 
    I am in Windows now^M$
    This is a file of Windows^M$
    There is a TAB^Ihere^M$
    ok end^M$
    [root@localhost test]# cat windows.txt | tr -d '\r' | cat -A
    I am in Windows now$
    This is a file of Windows$
    There is a TAB^Ihere$
    ok end$
    [root@localhost test]# cat windows.txt | tr -d '\r' | wc
          4      18      73
    [root@localhost test]#

 

22.cut:外部命令

  功能:移除文件中每行的分段,只保留指定的分段。

  格式:cut OPTION... [FILE]...

  常用选项:

    -b, --bytes=LIST:每行只保留被选中数量的字节

    -c, --characters=LIST:每行只保留被选中数量的字符

    -d, --delimiter=DELIM:定义分段数据的分隔符号

    -f, --fields=LIST:选择在指定分隔符的作用下,要保留的分段的位置编号

  退出状态:

    如果命令执行成功,状态返回值为0;如果命令执行失败,状态返回值为非0。

  使用举例:

    [root@localhost ~]# tail /etc/passwd | cut -d: -f1,3,4,7    
    libstoragemgmt:990:988:/sbin/nologin
    pulse:171:171:/sbin/nologin
    gdm:42:42:/sbin/nologin
    gnome-initial-setup:989:984:/sbin/nologin
    avahi:70:70:/sbin/nologin
    sshd:74:74:/sbin/nologin
    postfix:89:89:/sbin/nologin
    ntp:38:38:/sbin/nologin
    tcpdump:72:72:/sbin/nologin
    jobs:1000:1000:/bin/bash

23.sort:外部命令

  功能:将文本文件按行排序

  格式:sort [OPTION]... [FILE]...

  常用选项:

   -r, --reverse:执行倒序排序策略

   -n, --numeric-sort:执行按数字的数学含义的数值大小排序,默认是升序

   -f, --ignore-case:忽略字符大小写

   -u:删除执行结果中的连续的重复行(去重,unique)

   -t, --field-separator=SEP:使用指定的字符'SEP'做为字段定界符

   -k, --key=KEYDEF:按照字段定界符分隔的第"KEYDEF"列来整理,可以使用多次

  退出状态:

    如果命令执行成功,状态返回值为0;如果命令执行失败,状态返回值为非0。

  使用举例:

    [root@localhost test]# cat num.txt     
    172
    192
    16
    16777736
    254
    65536
    168
    [root@localhost test]# sort num.txt 
    16
    16777736
    168
    172
    192
    254
    65536
    [root@localhost test]# sort -n num.txt 
    16
    168
    172
    192
    254
    65536
    16777736
    [root@localhost test]#
    [root@localhost test]# tail -n 5 /etc/passwd
    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    postfix:x:89:89::/var/spool/postfix:/sbin/nologin
    ntp:x:38:38::/etc/ntp:/sbin/nologin
    tcpdump:x:72:72::/:/sbin/nologin
    jobs:x:1000:1000:zhao:/home/zhao:/bin/bash
    [root@localhost test]#
    [root@localhost test]# tail -n 5 /etc/passwd | sort -t: -k3 -n
    ntp:x:38:38::/etc/ntp:/sbin/nologin
    tcpdump:x:72:72::/:/sbin/nologin
    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    postfix:x:89:89::/var/spool/postfix:/sbin/nologin
    jobs:x:1000:1000:zhao:/home/zhao:/bin/bash


24.uniq:外部命令

  功能:报告或略过重复的行,连续且洗

  格式:uniq [OPTION]... [INPUT [OUTPUT]]

  常用选项:

    -c: 显示每行重复出现的次数;

    -d: 仅显示重复过的行;

    -u: 仅显示不曾重复的行;

  退出状态:

    如果命令执行成功,状态返回值为0;如果命令执行失败,状态返回值为非0。

  使用举例:

    [root@localhost test]# cat num.txt     
    128
    16
    16
    168
    65536
    16
    168
    [root@localhost test]# uniq num.txt 
    128
    16
    168
    65536
    16
    168
    [root@localhost test]# uniq -c num.txt 
          1 128
          2 16
          1 168
          1 65536
          1 16
          1 168
    [root@localhost test]# sort -n num.txt | uniq -c
          3 16
          1 128
          2 168
          1 65536
    [root@localhost test]#


25.type:内部命令

  功能:显示命令类型的相关信息

  格式:type [-afptP] name [name ...]

  常用选项:

    -t:输出“file”、“alias”或者“builtin”,分别表示给定的指令为“外部指令”、“命令别名”或者“内部指令”;

    -p:如果给出的指令为外部指令,则显示其绝对路径;

    -a:在环境变量“PATH”指定的路径中,显示给定指令的信息,包括命令别名。

  退出状态:

    如果命令执行成功,状态返回值为0;如果命令执行失败,状态返回值为非0。

  使用举例:

    [root@localhost test]# type -t ls    
    alias
    [root@localhost test]# type -t cd
    builtin
    [root@localhost test]# type -t cat
    file
    [root@localhost test]# type ls
    ls is aliased to `ls --color=auto'
    [root@localhost test]# type cd
    cd is a shell builtin
    [root@localhost test]# type cat
    cat is /usr/bin/cat
    [root@localhost test]#


26.nano:外部命令

  功能:一个文本编辑器,是pico的增强版克隆

  格式:nano [OPTIONS] [[+LINE,COLUMN] FILE]...

  常用选项:

    -h, -? --help:显示此信息 

    +行,列:从所指列数与行数开始 

    -A --smarthome:启用智能 HOME 键 

    -B --backup:储存既有文件的备份 

    -C <目录> --backupdir=<目录>:用以储存独一备份文件的目录 

    -D --boldtext:用粗体替代颜色反转 

    -E --tabstospaces:将已输入的制表符转换为空白 

    -F --multibuffer:启用多重文件缓冲区功能 

    -H --historylog:记录与读取搜索/替换的历史字符串 

    -I --ignorercfiles:不要参考nanorc文件 

    -K --rebindkeypad:修正数字键区按键混淆问题 

    -L --nonewlines:不要将换行加到文件末端 

    -N --noconvert:不要从DOS/Mac格式转换 

    -O --morespace:编辑时多使用一行 

    -Q <字符串> --quotestr=<字符串>:引用代表字符串 

    -R --restricted:限制模式 

    -S --smooth:按行滚动而不是半屏 

    -T <#列数> --tabsize=<#列数>:设定制表符宽度为 #列数 

    -U --quickblank:状态行快速闪动 

    -V --version:显示版本资讯并离开 

    -W --wordbounds:更正确地侦测单字边界 

    -Y <字符串> --syntax=<字符串>:用于加亮的语法定义 

    -c --const:持续显示游标位置 

    -d --rebinddelete:修正退格键/删除键混淆问题 

    -i --autoindent:自动缩进新行 

    -k --cut:从游标剪切至行尾 

    -l --nofollow:不要依照符号连结,而是覆盖 

    -m --mouse:启用鼠标功能 

    -o <目录> --operatingdir=<目录>:设定操作目录 

    -p --preserve:保留XON (^Q)和XOFF(^S) 按键 

    -q --quiet:沉默忽略启动问题, 比如rc 文件错误 

    -r <#列数> --fill=<#列数>:设定折行宽度为 #列数 

    -s <程序> --speller=<程序>:启用替代的拼写检查程序 

    -t --tempfile:离开时自动储存,不要提示 

    -u --undo:允许通用撤销[试验性特性] 

    -v --view:查看(只读)模式 

    -w --nowrap:不要自动换行 

    -x --nohelp:不要显示辅助区 

    -z --suspend:启用暂停功能 

    -$ --softwrap:启用软换行 

    -a, -b, -e, -f, -g, -j (忽略,为与pico 相容)


  几个常用的交互式命令:

     Ctrl+O:保存

     Ctrl+X:退出

     Alt+6:复制一整行

     Ctrl+K:剪贴一整行

     Ctrl+U:粘贴

     Ctrl+W:搜索,可以按Alt+W定位到下一个匹配的文本关键字

     Ctrl+Y:到上一页

     Ctrl+V:到下一页