零散知识点

    xiaoxiao2021-04-14  36

    1.whoami #查看当前用户

    [root@localhost ~]# whoami #查看当前用户 root [root@localhost mnt]#

    2.同时执行多条命令

    [root@localhost mnt]# ls data [root@localhost mnt]# mkdir linux;touch file #用 ; 隔开 [root@localhost mnt]# ls data file linux [root@localhost mnt]#

    3.递归归创建目录

    [root@localhost mnt]# ls [root@localhost mnt]# mkdir linux/xmj/dch mkdir: cannot create directory ‘linux/xmj/dch’: No such file or directory [root@localhost mnt]# mkdir linux/xmj/dch -p #递归创建 [root@localhost mnt]# cd linux/xmj/dch/ [root@localhost dch]# pwd /mnt/linux/xmj/dch [root@localhost dch]#

    4.seq

    [root@localhost mnt]# ls [root@localhost mnt]# for f in `seq 10`;do touch $f.txt;done [root@localhost mnt]# ls 10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt [root@localhost mnt]#

    5.间接创建文件

    [root@localhost mnt]# ls [root@localhost mnt]# echo > A.txt [root@localhost mnt]# ls A.txt [root@localhost mnt]# >B.txt [root@localhost mnt]# ls A.txt B.txt [root@localhost mnt]#

    6.cat也可以做追加 #必须掌握

    [root@localhost mnt]# cat B.txt [root@localhost mnt]# echo "The weather is so good" > B.txt [root@localhost mnt]# cat B.txt The weather is so good [root@localhost mnt]# cat > B.txt Ni hao today ^C #Ctrl+C终止任何的执行程序 [root@localhost mnt]# cat B.txt Ni hao today #把两个FOF中间的内容追加到文件中 |>表示覆盖|>>表示追加 #可同时追加多行 [root@localhost mnt]# cat >> /mnt/B.txt<<EOF > I am studing linux now > EOF [root@localhost mnt]# cat B.txt Ni hao today I am studing linux now [root@localhost mnt]#

    7.拷贝目录 -ap

    -ap #复制目录 -i #如果文件存在时,在覆盖之前会先询问 [root@localhost mnt]# ls A.txt B.txt [root@localhost mnt]# mkdir Linux [root@localhost mnt]# cd Linux/ [root@localhost Linux]# mkdir nihao [root@localhost Linux]# ll total 0 drwxr-xr-x. 2 root root 6 Apr 13 08:29 nihao [root@localhost Linux]# cp nihao/ /mnt/ cp: omitting directory ‘nihao/’ [root@localhost Linux]# cp -ap nihao/ /mnt/ [root@localhost Linux]# cd /mnt/ [root@localhost mnt]# ls A.txt B.txt Linux nihao [root@localhost mnt]#

    8.管道符 |

    #-v 不显示后边的 #awk sed grep 处理文件时,后面都可以直接跟文件 [root@localhost mnt]# cat B.txt Ni hao today I am studing linux now dch [root@localhost mnt]# cat B.txt | grep -v dch Ni hao today I am studing linux now #效率高 #中间有空格时,用引号引起来 #-v 过滤掉 | 不加 -v 就是只把后面的显示出来 [root@localhost mnt]# grep -v dch B.txt Ni hao today I am studing linux now [root@localhost mnt]# cat B.txt Ni hao today I am studing linux now dch [root@localhost mnt]# #sed -e[编译] '/所要处理的字符串/动作' # d——删除 不删除原内容,只是输出的时候不输出 # -n 取消默认的输出 [root@localhost mnt]# sed -e '/dch/d' B.txt Ni hao today I am studing linux now [root@localhost mnt]# cat B.txt Ni hao today I am studing linux now dch [root@localhost mnt]# #p打印 | ^不是 打印出不含 dch 的 [root@localhost mnt]# sed -n /[^dch]/p B.txt Ni hao today I am studing linux now [root@localhost mnt]# #awk # / 后面不跟参数 [root@localhost mnt]# awk /[^dch]/ B.txt Ni hao today I am studing linux now [root@localhost mnt]#

    9.alias 查看别名

    #alias 查看 #alias 别名 = '动作' 制作别名 #unalias 别名 取消别名 [root@localhost mnt]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' [root@localhost ~]# alias rs='echo "rs cmd is not allow to use."' [root@localhost ~]# rs rs cmd is not allow to use. [root@localhost mnt]# unalias cp #取消别名 #屏蔽掉别名: 1. / 2.绝对路径 #别名放置位置 家目录下的 ~/.bashrc [root@localhost ~]# cat ~/.bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi [root@localhost ~]#

    10.快捷键

    Ctrl+A 标移到行首 Ctrl+E 把光标移到行尾 [Ctrl] + [l] = 清屏。该快捷操作与在命令行键入 clear 作用相同

    11.find 参数也非常重要

    转载请注明原文地址: https://ju.6miu.com/read-669580.html

    最新回复(0)