美文网首页Linux简单命令行:文件/目录,sudo,包管理
命令行学习笔记(搜索和压缩相关)

命令行学习笔记(搜索和压缩相关)

作者: TW安洋 | 来源:发表于2016-12-08 10:33 被阅读9次
    • grep pattern file -- 使用正则表达式搜索文本
    • grep -r pattern dir -- 递归使用正则表达式搜索文本
    • command | grep pattern -- 以 command 输出为文本进行正则表达式搜索
    • locate file -- 查找文件

    效果如下:

    ➜  anyang cat file1     
    Hello, anyang!
    testhhhhhhhhhhhhh
    rrrrrrrrrrrrrrrr
    ddddddddddddd
    testfsfdsccvv
    ➜  anyang grep test* file1 
    testhhhhhhhhhhhhh
    testfsfdsccvv
    ➜  anyang grep -r test* .
    ./test/test1:test is a problem
    ./test/test3:test is nice
    ./file1:testhhhhhhhhhhhhh
    ./file1:testfsfdsccvv
    ➜  anyang cat file1 | grep test*
    testhhhhhhhhhhhhh
    testfsfdsccvv
    ➜  anyang locate grep
    /bin/bzegrep
    /bin/bzfgrep
    /bin/bzgrep
    /bin/egrep
    /bin/fgrep
    /bin/grep
    /bin/zegrep
    /bin/zfgrep
    /bin/zgrep
    /etc/alternatives/lzegrep
    /etc/alternatives/lzegrep.1.gz
    /etc/alternatives/lzfgrep
    
    • tar cf file.tar file(s) -- 将 file(s) 打包成名为 file.tar 的文件
    • tar xf file.tar -- 解压 file.tar 包中的所有文件
    • tar tf file.tar -- 列出 file.tar 包中的所有文件

    tar 常用参数列表:

    • c -- 建立压缩文件
    • t -- 列出压缩文件中的所有文件
    • x -- 解压压缩文件
    • f -- 指定压缩包的文件名
    • z -- 有gzip属性的
    • j -- 有bz2属性的
    • w -- 每一步操作都需要确认
    • v -- 显示所有过程

    效果如下:

    ➜  test ls
    file1  test1  test2  test3
    ➜  test tar cf test.tar test{1..3}
    ➜  test ls
    file1  test1  test2  test3  test.tar
    ➜  test mv test.tar ..           
    ➜  test cd ..
    ➜  anyang ls
    file1  learngit  test  test.tar
    ➜  anyang tar xf test.tar          
    ➜  anyang ls
    file1  learngit  test  test1  test2  test3  test.tar
    ➜  anyang tar tf test.tar
    test1
    test2
    test3
    
    • gzip file(s) -- 建立压缩文件,并删除原来的文件
    • gzip -c file(s) > file.gz -- 建立压缩文件并保留原来的文件
    • gzip -d file.gz -- 解压压缩文件,并删除原来的压缩文件,效果同gunzip

    效果如下:

    ➜  anyang ls
    file1  learngit  test
    ➜  anyang gzip file1 
    ➜  anyang ls
    file1.gz  learngit  test
    ➜  anyang touch newfile
    ➜  anyang ls
    file1.gz  learngit  newfile  test
    ➜  anyang gzip -c newfile > newfile.gz
    ➜  anyang ls
    file1.gz  learngit  newfile  newfile.gz  test
    ➜  anyang gzip -d file1.gz 
    ➜  anyang ls
    file1  learngit  newfile  newfile.gz  test
    

    相关资料:

    1. 29个你必须知道的Linux命令: http://www.imooc.com/article/1285
    2. 常用命令行介绍: https://github.com/iamcoach/console/blob/master/COMMANDS.md
    3. 常用命令行cheet sheet: https://bbs.excellence-girls.org/topic/167
    4. 书籍《鸟哥的Linux私房菜》: https://book.douban.com/subject/4889838/
    5. Ubuntu各种技巧:http://wiki.ubuntu.org.cn/UbuntuSkills

    相关文章

      网友评论

        本文标题:命令行学习笔记(搜索和压缩相关)

        本文链接:https://www.haomeiwen.com/subject/ffrjmttx.html