Linux命令_文本文件

1查找文件

  • find 实时查找
    • find filename -option [-print -exec -ok]
    • option:
      -name
      -perm(权限)
      -user
      -type(类型)
  • locate 快速查找,根据数据库索引查找文件
  • 列出文件列表:
    • ll -R 递归列出文件
    • ll -lh 显示文件大小
    • ll -S 按文件大小排序
    • ll -lt 按文件修改时间排序
    • ll -X 按扩展名排序

2查看文件

  • cat
    • cat -n 对所有行加行号
  • tac 反向显示
  • head
  • tail

3文本处理

  • grep
    • 整词匹配(忽略大小写):grep -W -i "word"
    • 行首:grep ^"abc"
    • 行尾:grep “xyz$"
  • tr
    • 删除所有‘string’中的字符:cat file | tr -d “ABC” 删除所有A、B、C
      *删除所有‘string’:cat file | tr -s “ABC” 删除所有ABC
  • sed
    • sed -n '3,6p' a.txt 静态显示3-6行
    • sed -n '/print$/' a.txt 显示已print结尾的行
    • sed -i '5d' a.txt 删除第五行,并修改文档
    • sed ‘2,3c change' a.txt 将第2-3行替换为’change‘
    • sed '/^$/d' file 移除空白行
  • wc统计
    • 按行统计:wc -l
    • 字符、字节:-m、-w
  • cut 选取
    • 自定义分隔符:cat file | cut -d ":" -f 2(显示第2个区域)
  • xargs
    • 自定义分隔符:cat file | xargs -d ":"
  • paste
    • 添加分隔符显示:paste -d '@&' file1 file2 file3
  • cp -r file1 file 2 复制目录
    排序
    去除
    统计

你可能感兴趣的:(Linux命令_文本文件)