zoukankan      html  css  js  c++  java
  • linux常用命令之查阅文件

    CAT

    cat – concatenate print files 连续的输出文件内容

    用法

    cat [-nbA] file

    选项

    • -n line number 输出行号
    • -b line number nonblank 输出空白行的行号
    • -A show All 显示特殊字符

    TAC

    tac – concatenate print files reverse 反序的查看文件

    MORE

    • more – 一页一页翻动
    • 功能键
    • 空格space 下一页
    • enter 下一行
    • /xxx 向下搜索xxx
    • n 搜索下一个
    • :f 显示文件名并显示行号
    • q 退出
    • b或ctrl+b 向上翻页

    LESS

    也是一页一页的翻动

    比more的功能更强大

    功能键

    • more有的less都有
    • 相对于more新增的:
    • pagedown 下一页
    • pageup 上一页
    • ?xxx 向上搜索
    • n搜索下一个
    • N反向搜索前一个

    HEAD

    head – output the first part of files 输出文件的前几行

    用法

    head [-n number] file

    选项

    • -n 后面接数字,表示输出前几行

    DEMO

    head -n 5 demo.txt

    输出demo.txt的前五行

    head -n -100 demo.txt

    不输出demo.txt的后100行

    TAIL

    tail – output the last part of files 输出文件的后几行

    用法

    tail [-n number] file

    选项

    • -n lines 后面接数字,表示输出后几行
    • -f follow output data as the files grow 持续输出文件的信息,当这个文件持续有数据写入的时候,-f就会持续输出出来,只有按下ctrl+c才会停止

    WHICH

    which – locate a command 定位命令

    which会在$PATH中查找命令

    选项

    • -a show all 显示出所有匹配的命令,不止是第一个

    注意

    • which是精确查找,加通配符也没用

    WHEREIS

    whereis – locate the binary、shource and manual page files for a command

    $PATH中查找指令的执行(二进制)文件、源文件和操作手册

    默认:binary、shource and manual page都会显示出来

    选项

    • -b binary 显示执行文件(二进制文件)
    • -m manual page 显示操作手册
    • -s source 显示源文件

    注意

    • whereis只支持精确搜索,不能模糊搜索
    • 在数据库中搜索,速度比find在硬盘搜索要快

    LOCATE

    locate – find files by name 查找文件

    和which、whereis不同的是,locate不仅仅只在$PATH中查找

    选项

    • -i ignore case 忽略大小写

    注意

    • locate也是在数据库搜索,比find在硬盘搜素要快
    • locate支持模糊搜索
    • updatedb可以更新数据库

    FIND

    查找文件

    在硬盘中查找

    用法

    find filename [option] [action]

    选项

    时间筛选

    • -atime、-mtime、-ctime,后面接数字
    • -mtime 5,表示修改时间在第五天前到第四天前的24小时
    • -mtime +5,表示修改时间在五天前
    • -mime -5,表示修改时间在五天内,不包括第五天!
    • -newer file,表示筛选出比file要新的文件

    用户筛选

    • -user name 筛选出owner为name的文件
    • -group name 筛选出group为name的文件
    • -nouser 筛选出owner不存在/etc/passwd的文件
    • -nogroup 筛选出group不存在/etc/group的文件
    • -uid id 筛选出文件的owner的id为id的文件,id在/etc/passwd
    • -gid id 筛选出文件的group的id为id的文件,id在/etc/group

    文件属性筛选

    • -name name 精确筛选文件名为name的文件
    • -size [+-] size 筛选出文件大小 大于(+)或小于(-)size的文件
    • -type type 一般文件:f,目录:d,链接文件:l,设备文件:b或c,socket文件:s,管道文件:p
    • -perm [+-] mode,mode为数字模式,筛选出权限为mode,或者包括全部(+)mode,或者包括任一组(-)mode

    -其他可进行的操作

    • -exec command 执行其他指令

    find / -size +500k -exec ls -l {} ;

    在根目录下以及根目录的所有子目录下,搜索出大小大于500kb的文件,并且列出详细信息

    {}:代表find搜索到的结果

    ; :表示其他指令的结束

    查看原文:http://139.129.55.235/2016/06/02/linux%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e4%b9%8b%e6%9f%a5%e9%98%85%e6%96%87%e4%bb%b6/
  • 相关阅读:
    js弹出DIV层
    .net 生成静态页面
    新开博客
    随机生成验证码
    ASP.NET错误处理方法总结
    webgis
    看樱花
    今天转载的笑话,挺好笑呵
    用Tomcat插件在Eclipse上搭建可跟踪调试的J2EE WEB开发环境
    关于JSTL的简单说明
  • 原文地址:https://www.cnblogs.com/wewill/p/5588731.html
Copyright © 2011-2022 走看看