zoukankan      html  css  js  c++  java
  • CentOS 文本操作命令(cat more less head tail tr wc state cut diff touch)

    1、cat 用于查看纯文本文件,显示行号,加-n参数,适合内容较少的情况

    2、more 用于查看纯文本文件,适合内容较多的情况

    3、less 用于查看纯文本文件,可以上下翻页

    4、head 用于查看纯文本文档的前 N行,head -n 20 2.txt

    5、tail 用于查看纯文本的后N行, “tail -n 20  文件名”

         tail的重要参数 -f,持续刷新一个文件的内容,当想要实时查看最新日志文件时,这特别有用,此时的命令格式为“tail -f  文件名”:  tail -f /var/log/messages

    6、 替换文本文件中的字符

    tr 命令用于替换文本文件中的字符,格式为“tr [原始字符] [目标字符]”

    将2.txt中所有小写字符替换成大写,并输出文件内容到4.txt
    [root@bigdata-senior01 ~]# cat 2.txt | tr [a-z] [A-Z] > 4.txt

     7、wc统计指定文本的行数、字数、字节数

    [root@bigdata-senior01 ~]# wc /var/log/messages
      8123  94639 688718 /var/log/messages

    8、stat查看文本状态

    [root@bigdata-senior01 ~]# stat 1.txt
      文件:"1.txt"
      大小:13        	块:8          IO 块:4096   普通文件
    设备:fd00h/64768d	Inode:33575015    硬链接:1
    权限:(0666/-rw-rw-rw-)  Uid:(    0/    root)   Gid:(    0/    root)
    最近访问:2019-01-05 22:57:28.584806141 +0800
    最近更改:2019-01-05 22:57:26.376805943 +0800
    最近改动:2019-01-05 22:57:26.376805943 +0800
    创建时间:-

    9、cut用于按列提取文本数据

    使用-f 参数来设置需要看的列数,还需要使用-d 参数来设置间隔符号
    [root@bigdata-senior01 ~]# cut -d: -f1 /etc/passwd root bin daemon adm lp sync
    ... ...

    查看第1,7列
    [root@bigdata-senior01 ~]# cut -d: -f1,7 /etc/passwd
    root:/bin/bash
    bin:/sbin/nologin
    daemon:/sbin/nologin
    adm:/sbin/nologin
    lp:/sbin/nologin
    sync:/bin/sync
    ... ...

    10、diff用于比较多个文本文件的差异

    第1,3行不同
    [root@bigdata-senior01 ~]# diff 1.txt 2.txt -c
    *** 1.txt    2019-01-06 15:41:37.471349686 +0800
    --- 2.txt    2019-01-06 15:42:18.231353343 +0800
    ***************
    *** 1,3 ****
    ! 这就对了
    ! 这个一个测试
    ! 我不是说笑的。
    --- 1,3 ----
    ! 这就不对了
    ! 这是一个测试
    ! 我就是说笑的。

     11、touch用于创建一个空白文本,touch还有一个用途就是修改文件的时间

    -a  仅修改“读取时间”(atime) 
    -m  仅修改“修改时间”(mtime) 
    -d  同时修改 atime 与 mtime 
    [root@bigdata-senior01 ~]# ll 1.txt
    -rw-rw-rw-. 1 root root 54 1月   6 15:41 1.txt
    
    [root@bigdata-senior01 ~]# echo "我追加了一条文本到末尾" >> 1.txt
    
    [root@bigdata-senior01 ~]# ll 1.txt
    -rw-rw-rw-. 1 root root 88 1月   6 15:47 1.txt
    
    [root@bigdata-senior01 ~]# touch -d "2019-01-06 15:41" 1.txt
    
    [root@bigdata-senior01 ~]# ll 1.txt
    -rw-rw-rw-. 1 root root 88 1月   6 15:41 1.txt
     
  • 相关阅读:
    Mobile GMaps - Google Map移动版
    365Key今天不能用了,感觉不爽
    推荐:对个人免费的杀毒软件[avast!]
    向 Visual Studio 2005 Tools for Office 迁移时,将 VBA 代码转换为 Visual Basic .NET
    令人向往的3000年生活(转载)
    也说技术人员创业
    痛恨3721的朋友们,装个avast! Antivirus吧
    很Cool很全的Google Map的应用
    关于.net的企业应用开发
    天天网摘(20050704)
  • 原文地址:https://www.cnblogs.com/asker009/p/10226689.html
Copyright © 2011-2022 走看看