zoukankan      html  css  js  c++  java
  • Linux系统常用命令示例

    1、在跟下创建一个目录,目录的名字为data

    # mkdir /data
    2、在data目录里创建一个文件,文件名为yunjisuan.txt

    # touch /data/yunjisuan.txt
    3、给yunjisuan.txt增加内容“I am studying linux”

    # cd yunjisuan
    # echo "I am studying linux" >> yunjisuan.txt
    4、把yunjisuan.txt拷贝到根下的/tmp目录里

    # cp yunjisuan.txt /tmp
    5、把/data目录移动到/root目录里

    # mv /data /root
    6、进入/root目录下的data目录里,然后在当前目录下一次性创建文件yunjisuan01.txt、yunjisuan02.txt、yunjisuan03.txt、yunjisuan04.txt

    # touch yunjisuan{01..04}.txt
    7、回到root用户的家目录里,一次性删除当前目录下的data目录里的所有文件,但唯独保留yunjisuan03.txt不删

    (1)# cd ~
    # rm -rf `ls | grep -v "yunjisuan03"`
    (2)# find . -type f ! -name "yunjisuan03" | xargs rm -rf
    (3)# ls | grep -v "yunjisuan03" | xargs rm -rf
    8、返回上级目录,并删除当前目录下的data目录

    # rm -rf /data
    9、已知当前目录,有若干文件和目录,一次性删除以.sh结尾的所有文件

    (1)# find -type f -name "*.sh" | xargs rm -rf
    (2)# find -type f -name "*.sh" -exec rm -rf {} ;
    10、已知当前目录,有若干文件和目录,一次性将所有以chen开头的目录移动到/tmp目录下

    (1)# find -type d -name "chen*" | xargs -i mv {} /tmp
    (2)# find -type d -name "chen*" -exec mv {} /tmp ;
    11、已知/data目录里,有若干文件和目录,找到所有文件名里面含有LOL的文件,一次性复制到/mnt目录里

    (1)# find -type f -name "*LOL*" | xargs -i cp {} /mnt
    (2)# find -type f -name "*LOL*" -exec cp {} /mnt ;
    12、已知yunjisuan.txt文件内容,保持源文件内容不变,输出内容时去掉第5行内容后,输出结果

    (1)# cat yunjisuan.txt | grep -v "I am benet"

    (2)# head -4 test && tail -6 test
    (3)# sed '/5/d' yunjisuan.txt
    (4)# awk '!/5/' yunjisuan.txt

    13、创建目录/yunjisuan/test,即创建/yunjisuan目录及/yunjisuan/test目录
    # mkdir -p /yunjisuan/test/
    14、只查看文件ett.txt(共100行)内第20行到第30行内容

    (1)# head -30 test && tail -11 test
    (2)# sed -n '20,30p' ett.txt
    (3)# awk 'NR>19 && NR<30' ett.txt
    15、把/yunjisuan目录及其子目录下所有以扩展名.sh结尾的文件,文件中包含yunjisuan的字符串全部替换为welcome

    # find /yunjisuan - type f -name "*.sh" | xargs sed -i 's#yunjisuan#welcome#g'

  • 相关阅读:
    Meten Special Activities II
    Meten Special Activities II
    Meten Special Activities II
    Meten Special Activities II
    Meten Special Activities
    Meten Special Activities
    Meten Special Activities
    Meten Special Activities
    Meten Special Activities
    冒泡排序和选择排序
  • 原文地址:https://www.cnblogs.com/daisy118/p/9826914.html
Copyright © 2011-2022 走看看