zoukankan      html  css  js  c++  java
  • linux基本命令

    find

    find /root/data -type f -exec rm -rf {} ;

    find /root/data -type f | xargs rm -f
    find -type 按文件类型来查找

    案例:

    删除一个目录下的所有文件,但是保留一个指定文件
    方法一:
    find /root/ -type f ! -name "file10" | xargs rm -f
    find /root/ -type f ! -name "file10" -exec rm -rf {} ;
    
    -exec 处理查找的结果(对前面的结果进行处理)
    {} 表示查找到的内容
    ; 转译
    

    复制的时候,名字相同,不会提示覆盖

    /bin/cp /mnt/test.txt /tmp/test.txt 全路径
    cp /mnt/test.txt /tmp/test.txt 加

    alias 设置别名
    unalias 取消别名

    案例2:

    只看一个文件的20到30行
    head -30 test.txt | tail -11
    打印行号
    sed -n '20,30p' test.txt
    
    sed 's#oldboy#oldgirl#g' test.txt 将oldboy替换成oldgirl (只是替换了输出,文件没有替换)
    sed -i 's#oldboy#oldgirl#g' test.txt 表示替换 g表示全局,#可以用/@替换
    

      

    seq 打印序列
    tail -f 跟踪文件的实时变化

    awk 过滤内容,打印,删除
    过滤内容(取列)
    awk '{print $1}' 文件 $1 第一列, $2 第二列
    awk -F ":" '{print $1}' 文件 -F 是以什么味分隔符
    awk -F ":" '{print $1','$2','$3}' 中间有逗号来分割

    awk '{if(NR<31 && NR>19) printf $1" "}' test.txt NR是行号


    find /root/data -type f -name "test.txt" | xargs sed -i 's/oldboy/oldgirl/g'

    xargs 

    cat >>test.txt<<EOF 
    1 2 3 4 5
    6 7 8 9 10
    EOF
    
    [root@lilidun ~]# cat test.txt 
    1 2 3 4 5
    6 7 8 9 10
    [root@lilidun ~]# xargs < test.txt 
    1 2 3 4 5 6 7 8 9 10
    [root@lilidun ~]# xargs -n 4 < test.txt 
    1 2 3 4
    5 6 7 8
    9 10
    

    sed

    sed -i 's/原字符串/替换字符串/'
  • 相关阅读:
    Enum, Generic and Templates
    Writing A Threadpool in Rust
    A First Look at Rust Language
    Closures in OOC
    Complexity Behind Closure
    Introduction to OOC Programming Language
    OOC,泛型,糟糕的设计。
    Enlightenment笔记
    Machine Learning/Random Projection
    Machine Learning/Introducing Logistic Function
  • 原文地址:https://www.cnblogs.com/lilidun/p/6092259.html
Copyright © 2011-2022 走看看