[100]第二波命令小结

设计到的命令汇总

1.mkdir
2.ls
    -l
    -d 显示目录
    -F 给文件夹结尾加/标识
    -a 以.开头的都是隐藏文件
    -rt 按照修改时间倒序排列(最新修改的在最下)
3.cd
4.pwd
5.touch
6.vi
7.vim
8.echo
9.cat
    -n 显示行号
10.xargs -n 数字,分组
    echo stu{1..20}.md|xargs -n 1 > 1.md
11.cp
    -a 等价于-pbr
    -f(force)
    -r(recursive)递归

12.rm
    1.以tmp为回收站
    2.先cd,后find . -name ""|xargs rm -f
13.mv

14.find:
    -type f(file) d(directory) c(character) b(block) s(socket) l(link)
    -name
    -size
    -mtime 修改时间: +7(超过7天) 7 -7(7天内)
    -maxdepth 查找深度
    ! 取反, -a(and)交集(默认), -o or并集
    -exec
        find . -type f -mtime +7 |xargs rm -f
        find . -type f -mtime +7 -exec rm -f {} ;
15.grep:三剑客老三
    -v 排除: 生产监控进程: ps -ef|grep "/sshd"|grep -v "grep"
    -ABC
    -n  对匹配到的内容
    -E  =egrep, 可以同时过滤多个(或),cat svc.txt|grep -E "rsyslog|sshd|network|crond|sysstat" |awk '{print "chkconfig",$1,"on"}'

16.head
    -n5: 习惯head -5
17.tail
18.alias
19.unalias
20.seq  sequence  -s指定分割符
        seq 开始 结束: seq 1 10
        seq 开始 公差 结束: seq 1 2 10
21.sed
    -n 取消默认输出,仅输出匹配想要的
    -p 打印,  sed -n'20'p a.log; sed -n '20,30'p a.log
              过滤功能(正则):sed -n '/^d/p'
    g与s联合使用,表示替换: sed -i 's#maotai#maotai#g' a.log #是分隔符

22.awk #过滤/输出内容,一门语言.
        NR 行号: awk 'NR>30 && NR<40'
                awk 'NR>30 && NR<40 {print $2}' m.txt
        $1 第一列 $2第二列 $0整个行:
                awk '{print $1,$2}'
                awk '{print $1"#"$2}'
                awk '{if($2>1) print$0}'
                cat svc.txt|grep -E "rsyslog|sshd|network|crond|sysstat" |awk '{print "chkconfig",$1,"on"}'
        显示行号:
            awk '{print NR,$0}'
        过滤功能(正则): 正则匹配: awk '/^d/'
        -F 分隔符 awk -F '[: ]+'

23,useradd
24,passwd
非交互式改密码: echo "12345"|passwd --stdin maotai

25.uname:
    -m 32or64
    -r 内核版本
    -a(all)
    -n(主机名)
26.
27.
28.


29.shutdown -h now
    -r
    -h
30.reboot(init 6)重启, shutdown -r now
31.history  -c清空所有
            -d删除指定的历史记录
32.dmeseg 显示系统故障信息
33.ifup和ifdown, 启动停止网卡
34.nl number lines,显示文件行号
35.less 和more相反,回车一次一行,空格一次一屏,按b可以一次回退一屏.
36.more (不常用) 按页一次一屏,不能回退
37, wc -l(lines) 显示总行数
        生产监控进程: ps -ef|grep "/sshd"|grep -v "grep"|wc -l
38,chkconfig 设置开机自启动,默认管理2345级别
        也可以:/etc/rc.local
        --list 显示所有
            --list sshd
        --level 234
            chkconfig sshd on/off
            chkconfig --level 234 sshd on/off

            chkconfig --list        #列出所有的系统服务
            chkconfig --add httpd        #增加httpd服务
            chkconfig --del httpd        #删除httpd服务
            chkconfig --level httpd 2345 on        #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
            chkconfig --list        #列出系统所有的服务启动情况
            chkconfig --list mysqld        #列出mysqld服务设置情况
            chkconfig --level 35 mysqld on        #设定mysqld在等级3和5为开机运行服务,--level 3

第二波预测试:

1,过滤出已知当前目录下test/中所有一级目录(不含test/下的子目录的子目录,及隐藏目录)
方法1: 目录是d
ls -l|grep "^d"

方法2: 给目录加上/
ls -lF|grep "/$"

方法3: find找一层,排除当前目录
[root@n1 test]# find ./ -maxdepth 1 -type d ! -name '.'
./dir1
./dir2

方法4: 第二列(硬连接大于1的)
ls -l|awk '{if($2>1) print$0}'

方法5: sed过滤功能(正则)
ls -l|sed -n '/^d/p'
ls -l|sed -n '//$/p'

方法6: awk过滤功能(正则)
ls -l|awk '/^d/'
ls -l|awk '//$/'
2.查找最新创建的两个文件/
- 造数据
for i in `seq 14`;do date -s "2018/01/$i";touch access_www_$(date +%F).log;done
[root@n1 test]# find . -type f -mtime +7
./access_www_2018-01-01.log
./access_www_2018-01-02.log
./access_www_2018-01-03.log
./access_www_2018-01-04.log
./access_www_2018-01-05.log
./access_www_2018-01-06.log
./access_www_2018-01-07.log
./access_www_2018-01-08.log
./access_www_2018-01-09.log
./access_www_2018-01-10.log
./access_www_2018-01-11.log
./access_www_2018-01-12.log
./access_www_2018-01-13.log
./access_www_2018-01-14.log


find . -type f -mtime +7 |xargs rm -f

find . -type f -mtime +7 -exec rm -f {} ;

rm -f `find . -type f -mtime +7`
3.打印文件内容带行号:
造数据: echo stu{1..20}.md|xargs -n 1 > nginx.conf

cat -n nginx.conf
grep -n . nginx.conf
vim: set nu
awk '{print NR,$0}' nginx.conf
原文地址:https://www.cnblogs.com/iiiiher/p/8503922.html