练习06

作者: JevonWei | 来源:发表于2017-06-15 22:53 被阅读0次

    20170523
    1、显示/var目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件或目录
    ls 1[[:digit:]][[:lower:]]
    2、显示/etc目录下以任意一位数字开头,且以非数字结尾的文件或目录
    ls -d /etc/[[:digit:]][^[:digit:]]
    3、显示/etc/目录下以非字母开头,后面跟了一个字母及其它任意长度任意字符的文件或目录
    ls -d /etc/[^[:alpha:]][[:alpha:]]

    4、显示/etc/目录下所有以rc开头,并后面是0-6之间的数字,其它为任意字符的文件或目录
    ls -d /etc/rc[0-6]*
    5、显示/etc目录下,所有以.d结尾的文件或目录
    ls -d /etc/.d
    6、显示/etc目录下,所有.conf结尾,且以m,n,r,p开头的文 件或目录
    ls -d /etc/[mnrp]
    .conf
    7、只显示/root下的隐藏文件和目录
    ls -aI "[^.]" /root
    ls -a --ignore=[^.]
    /root
    8、只显示/etc下的非隐藏目录
    ll /etc/ | grep ^d
    ls -d /etc/*/

    1、对/etc/passwd 取用户名和UID,并对UID倒序排序
    cut -d: -f1,3 /etc/passwd|sort -t: -k2 -nr

    2、取分区利用率最大值
    df |tr -s " " %|cut -d% -f5|sort -nr|head -n1
    df -i |tr -s " " %|cut -d% -f5|sort -nr|head -n1

    3、取出http服务访问次数最高的IP
    cut -d" " -f1 /var/log/httpd/access_log |sort|uniq -c| sort -nr|head -n1|tr -s " "|cut -d" " -f3

    4、取出UID最大的用户,UID和shell
    sort -t: -k3 -n /etc/passwd|tail -n1|cut -d: -f1,3,7

    5、取/tmp/数字权限
    stat /tmp|head -n4|tail -n1|cut -d "(" -f2|cut -d / -f1

    6、取/mnt/Packages下rpm包的编译版本
    ls *.rpm |rev|cut -d. -f2|rev|sort |uniq -c
    ls rpm|egrep -o "<[_0-9a-zA-Z].rpm" |cut -d. -f1|sort |uniq -c
    ls *rpm|egrep -o "<[^.]+.rpm" |cut -d. -f1|sort |uniq -c
    ls *rpm|egrep -o "[^.]+.rpm" |cut -d. -f1 |sort |uniq -c


    7、卸载rpm包,并恢复
    rpm -e rpm --nodeps

    20170525
    1、cmd linkfile
    readlink 文件


    2 硬,软链接的区别
    硬链接
    硬链接必须在同一个分区中创建,不能跨分区,跨分区只能用软链接
    硬链接不支持对目录创建
    不复制原数据,仅分配一个inode号和文件名
    链接文件跟原文件使用同一个inode号
    硬链接工作的相对路径相对于当前目录
    链接文件没有依赖性关系,链接数会随着链接次数增加加1,
    软链接
    可以对目录进行
    可以跨分区
    指向的是另一个文件的路径;其大小为指向的路径字符串的长度;不增加或减少目标文件inode的引用计数;
    inode号跟原文件不一致,会分配其他的inode号
    删除链接原文件,则链接指向失效
    软链接用相对路径时相对的不是当前工作目录,而是相对软链接工作路径
    3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
    tr 'a-z' 'A-Z' </etc/issue >/tmp/issue.out
    4、将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中
    who | tr 'a-z' 'A-Z' > /tmp/who.out
    5、一个linux用户给root发邮件,要求邮件标题为”help”,邮件正文如下:
    Hello, I am 用户名,The system version is here,pleasehelp me to check it
    ,thanks!
    操作系统版本信息
    (echo "hello,I am $USER,the system version is here,pleasehelp me to check it,thnaks! ";uname -o) | mail -s "hello" root
    6、将/root/下文件列表,显示成一行,并文件名之间用空格隔开
    ls /root | tr -s '\n' ' '
    7、计算1+2+3+..+99+100的总和
    echo {1..100} | tr -s ' ' '+' | bc
    8、删除Windows文本文件中的‘^M’字符
    tr -s '^M' ' ' < qq.txt
    9、处理字符串“xt.,l 1 jr#!$mn2 c/fe3 uz4”,只保留其中的数字和空格
    echo ‘xt.l 1 jr#cdmn2 ,,,c
    /fe3 uz4’ | tr -dc '[:digit:][:space:]'
    10、将PATH变量每个目录显示在独立的一行
    echo $PATH | tr ':' '\n'
    11、将指定文件中0-9分别替代成a-j
    tr -t [0-9] [a-j] < q
    12、将文件中每个单词(由字母组成)显示在独立的一行,并无空行
    tr -s ' :' '\n' < q

    20170531
    1 、显示/proc/meminfo 文件中以大小s 开头的行( 要求:使用两种方法)
    cat /proc/meminfo | grep -i ^s
    cat /proc/meminfo | grep ^[Ss]
    grep -e ^s -e ^S /proc/meminfo
    2 、显示/etc/passwd 文件中不以/bin/bash 结尾的行
    grep -v /bin/bash$ /etc/passwd
    3 、显示用户rpc 默认的shell 程序
    grep ^danran> /etc/passwd | cut -d: -f7
    4 、找出/etc/passwd 中的两位或三位数
    grep "<[0-9]{2,3}>" /etc/passwd
    5 、显示CentOS7 的/etc/grub2.cfg 文件中,至少以一个空白字符开头的且后面存非空白字符的行
    grep '[[:space:]]+[[:space:]]' /etc/grub2.cfg
    6 、找出“netstat -tan” 命令的结果中以‘LISTEN’ 后跟任意多个空白字符结尾的行
    netstat -tan | grep 'LISTEN[[:space:]]$'
    7 、显示CentOS7 上所有系统用户的用户名和UID
    cut -d: -f1,3 /etc/passwd | grep '<[0-9]{1,3}>'|grep -v root
    8 、添加用户bash 、testbash 、basher 、sh 、nologin( 其shell为/sbin/nologin), 找出/etc/passwd 用户名同shell 名的行
    grep '^(.
    ):.\1$' /etc/passwd
    grep '(^[[:alnum:]]+>).
    \1$' /etc/passwd
    9 、利用df 和grep ,取出磁盘各分区利用率,并从大到小排序

    1 、显示三个用户root 、mage 、wang 的UID 和默认shell
    egrep '^(danran|dan)' /etc/passwd | cut -d: -f 1,7
    2 、找出/etc/rc.d/init.d/functions 文件中行首为某单词(包括下划线) 后面跟一个小括号的行
    egrep '^([[:alnum:]]|)+()' -o /etc/rc.d/init.d/functions
    grep -E -o '^[
    [:alpha:]]+()' /etc/rc.d/init.d/functions
    3 、使用egrep 取出/etc/rc.d/init.d/functions 中其基名
    echo /etc/rc.d/init.d/functions | egrep -o '[^/]+$'
    echo '/mnt/sdc' | grep -o -E '[^/]+?$'
    4 、使用egrep 取出上面路径的目录名‘
    echo /etc/rc.d/init.d/functions | egrep -o '.<'
    echo /etc/rc.d/init.d/functions | egrep -o '^/.
    /'
    echo '/mnt/sdc' | grep -o -E '/.*/[ ]' | egrep -o '^/./'
    5 、统计last 命令中以root 登录的每个主机IP 地址登录次数
    last | egrep -o '^root>.
    [0-9].[0-9]{1,3}' |tr -s ' ' | cut -d' ' -f3|sort -n | uniq -c
    last | egrep '^root>.*[0-9].[0-9]{1,3}' | egrep -o '([0-9]{1,3}.){3}[0-9]{1,3}'| sort -n | uniq -c
    6 、利用扩展正则表达式分别表示0-9 、10-99 、100-199、 、200-249 、250-255

    7 、显示ifconfig 命令结果中所有IPv4 地址
    ifconfig | egrep -o '([0-9]{1,3}.){3}[0-9]{1,3}'
    8 、将此字符串:welcome to magedu linux 中的每个字符去重并排序,重复次数多的排到前面
    echo 'welcome to danran' | grep -o '.' | sort | uniq -c | sort

    1 、复制/etc/profile 至/tmp/ 目录,用查找替换命令删除/tmp/profile 文件中的行首的空白字符
    2 、复制/etc/rc.d/init.d/functions 文件至/tmp 目录,用查找替换命令为/tmp/functions 的每行开头为空白字符的行的行首添加一个#号
    3、在vim 中设置tab 缩进为4 个字符
    4 、复制/etc/rc.d/init.d/functions 文件至/tmp 目录,替换/tmp/functions 文件中的/etc/sysconfig/init 为/var/log
    5 、删除/tmp/functions 文件中所有以# 开头,且# 后面至少有一个空白字符的行的行首的#号

    20170608
    1、编写脚本/bin/per.sh,判断当前用户对指定的参数文件,是否不可读并且不可写
    #!/bin/bash
    # filename per.sh
    # author:danran
    # time is 2017-06-08
    [ ! -r $1 -a ! -w $1 ] && echo "$1 file not read and not write"
    2、编写脚本/root/bin/excute.sh ,判断参数文件是否为sh后缀的普通文件,如果是,添加所有人可执行权限,否则提示用户非脚本文件
    #!/bin/bash
    # filename excute.sh
    # author:danran
    # time is 2017-06-08
    [ $# == 0 ] && read -p "please input fimename" name || name=$1
    [ -f $name ] && [[ "$name" =~ .sh$ ]] && chmod a+x $name || echo "$name not scripts file"
    3、查找/var目录下属主为root,且属组为mail的所有文件
    find /var -user root -group mail
    4、查找/var目录下不属于root、lp、gdm的所有文件
    -find /var ! ( -user root -a -user lp -a -user mail )
    5、查找/var目录下最近一周内其内容修改过,同时属主不为root,也不是postfix的文件
    find /var -ctime -7 -not ( -user root -a -user postfix )
    6、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件
    find / -atime -7 -nouser -o -nogroup
    7、查找/etc目录下大于1M且类型为普通文件的所有文件
    find /etc/ -size +1M -type f
    8、查找/etc目录下所有用户都没有写权限的文件
    find /etc -not -perm /222
    9、查找/etc目录下至少有一类用户没有执行权限的文件
    find /etc -not -perm -111
    10、查找/etc/init.d目录下,所有用户都有执行权限,且其它用户有写权限的文件
    find /etc/init.d/ -perm -111 -perm -002

    20170609
    1、rm -f /usr/bin/tree,用两种方法恢复之
    方法一
    rpm2cpio /mnt/Packages/tree* | cpio -tv 预览查看tree包中的文件
    rpm2cpio /mnt/Packages/tree* | cpio -id ./usr/bin/tree 单独解压./usr/bin/tree文件到当前目录
    cp usr/bin/tree /usr/bin



    方法二:
    rpm -ivh tree-1.6.0-10.el7.x86_64.rpm --replacepkgs 重新安装tree包
    2、/usr/bin/java来自哪个rpm包
    rpm -q --whatprovides java


    3、开机创键yum库文件的脚本reset.sh

    !/bin/bash

    mkdir /etc/yum.repos.d/backup
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
    cat > /etc/yum.repos.d/base.repo << EOF
    [base]
    name=danran
    baseurl=file:///mnt
    gpgcheck=0
    enabled=1
    EOF

    相关文章

      网友评论

          本文标题:练习06

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