码迷,mamicode.com
首页 > 系统相关 > 详细

[100]linux常用命令参数小结

时间:2018-03-15 11:11:51      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:df -h   nali   http   e2fs   ssi   pass   local   alt   file   

1.mkdir
2.ls
    -l
    -d 显示目录
    -F 给文件夹结尾加/标识
    -a 以.开头的都是隐藏文件
    -rt 按照修改时间倒序排列(最新修改的在最下)
    ls -lhrt #最新的在下面
    
3.cd
4.pwd
5.touch
6.vi
7.vim
8.echo
    配合 > >>
    -n 不换行
    -e 内容携带转义(\n回车 \t tab) $echo -e 'mao\ntai'
9.cat
    -n 显示行号
10.xargs -n 数字.分组
    echo stu{1..20}.md|xargs -n 1 > 1.md
    find . -type f|xargs sed -i 's#<script type="text/javascript" src=http://%4%66ccxxx&W@#@$@#$@$%@#$SFADS@#$></script>##g';
    find . -type f -name '1.md'|xargs -i mv {} /tmp/
11.cp
    -a 等价于-pbr
    -f(force)
    -r(recursive)递归

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

14.find:    http://www.cnblogs.com/iiiiher/p/8507948.html
    -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 -name '1.md'|xargs -i mv {} /tmp/
        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
    -E 等价于egrep '1|2'
    -o 只显示匹配到的内容
    -n  对匹配到的内容显示行号
    -E  =egrep. 可以同时过滤多个(或).cat svc.txt|grep -E "rsyslog|sshd|network|crond|sysstat" |awk '{print "chkconfig".$1."on"}'
    -i 不区分大小写

16.head
    -n5: 习惯head -5
    
17.tail
18.alias
19.unalias
20.seq  sequence  -s指定分割符
         seq 1 10   #开始 结束
         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 #是分隔符

    sed过滤功能:
        ls -l|sed -n '/^d/p'
        ls -l|sed -n '/\/$/p'

    过滤文件权限:stat maotai.txt |sed -nr '4s#^.*\(0(.*)/-.*$#\1#gp'
    过滤ip: ifconfig eth0|sed -nr '2s#^.*net (.*)  net.*$#\1#gp'


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/'
            (过滤目录)ls -l|awk '/^d/'
            (过滤目录)ls -l|awk '/\/$/'
        -F 分隔符 .以多个分割符分割 awk -F '[: ]+'
            过滤文件权限: stat maotai.txt |sed -nr '4s#^.*\(0(.*)/-.*$#\1#gp'
            过滤ip: ifconfig eth0|sed -nr '2s#^.*net (.*)  net.*$#\1#gp'


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

25.uname:
    -m #--machine 32or64
    -r #--release 内核版本
    -a #--all
    -n #--nodename 

26.
27.
28.init: 切换运行级别.后面接对应级别的数字.例如: init 6重启. init 0关机.


29.shutdown -h now
    -r  # reboot
    -h # halt

30.reboot(init 6)重启. 
    shutdown -r now


31.history(HISTSIZE=1000控制.bash_history记多少条,先清空后设置)
            -c #Clear清空所有历史
            -d #删除某一条记录, history -d 222
            -r #清除当前session的
            -w #Write立即更新.bash_history
            
last    >/var/log/wtmp    # 成功登录用户
lastb   >/var/log/btmp    # 尝试登录信息
lastlog >/var/log/lastlog # 显示最近登录信息

[设置linux系统history相关变量,命令时间、保存history条数,多session共享history](http://coolnull.com/4013.html)

[参考: 从清除历史跑路](http://topspeedsnail.com/clear-last-linux-login-log/)
> /var/log/wtmp
> /var/log/btmp
> /var/log/lastlog
> /root/.bash_history  #如果要删除某几条.则e

- 不记录日志
$ <空格>command
/etc/profile HISTSIZE=1000设置为0.不记录

HISTSIZE=3000     # HISTSIZE 定义了 history 命令输出的记录数.
HISTFILESIZE=3000 # HISTFILESIZE 定义了在 .bash_history 中保存命令的记录总数.
HISTSIZE=0        # 禁用history


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(/etc/rc.local) # 设置开机自启动.默认管理2345级别
        --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

39.tar
    -zcvf 
    -j 
    -x
    -X
    -N 
    -p
    -P
    -C          # 指定解压到哪
    --exclude   # 排除目录或文件
    参考: http://www.cnblogs.com/iiiiher/p/8571517.html
    tar -cvf test.tgz test/ --exclude *.txt --exclude dir1

40.cut 切割 取列 -d分隔符 -f取列 -c字符
    -d 以什么分割
    -c 多少个字符 -c2-10

41.tr       # 逐个字符替换
42.stat     # 显示文件和文件系统状态(查看文件属性)
43.file     # 查看文件的类型
44.last     # 查看用户登录信息 /var/log/wtmp数据文件
45.lastlog  # 显示最近用户登录信息. /var/log/wtmp
46.df -h
47.dumpe2fs # 查看文件系统的内部信息(元数据)
48.tree 
    -L 层 
    -d 目录
    tree -Ld 1 /etc/ # 显示一级目录
    
49.id       # 查看用户和组的信息
50.ln       # 创建软硬链接 -s软(readlink)
51.du  -sh  # 查看文件和目录的大小

52.which    # 从PATH变量所在路径查找程序路径


特殊变量:
PATH 所有命令的路径所在地.用冒号隔离
LANG 字符集变量

[100]linux常用命令参数小结

标签:df -h   nali   http   e2fs   ssi   pass   local   alt   file   

原文地址:https://www.cnblogs.com/iiiiher/p/8571563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!