[100]linux常用命令參數小結
阿新 • • 發佈:2018-03-15
.html file sql 設定 隔離 time max exec rgs
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常用命令參數小結