在管道符后面进行截取前面命令的输出。html
cut -d " " 指定分割条件,好比 ":" ,就是以:进行分割。每到一个:就是一段。linux
-f 是指定截取哪一段。后面跟数字几,就是截取几段。若是想1到4段都要。就是-f 1-4正则表达式
[root@localhost ~]# cat /etc/passwd |head -2 root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin [root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1 root bin [root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2 root:x bin:x [root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2,4 root:x:0 bin:x:1
[root@localhost ~]# cat /etc/passwd |head -2 |cut -c 4 t :
Linux sort命令的几个细节问题(sort并未按ASCII排序)http://www.javashuo.com/article/p-tyuagcmx-ee.htmlshell
[root@localhost ~]# cat 1.txt 43 35 67 907890 hrshs hsga agsfh .,12125 43 &%#@ ^$%$ @%#
[root@localhost ~]# sort 1.txt ^$%$ @%# &%#@ .,12125 35 43 43 67 907890 agsfh hrshs hsga
[root@localhost ~]# sort -n 1.txt ^$%$ @%# &%#@ .,12125 agsfh hrshs hsga 35 43 43 67 907890
[root@localhost ~]# wc -l 1.txt 12 1.txt
[root@localhost ~]# wc -m 1.txt 58 1.txt
[root@localhost ~]# wc -w 1.txt 12 1.txt
[root@localhost ~]# cat 2.txt 1111 111 1111 1111 2222 2222 2222 3333 3333 3333 4 5 [root@localhost ~]# unip 2.txt -bash: unip: 未找到命令 [root@localhost ~]# uniq 2.txt 1111 111 1111 2222 3333 4 5
结果发现是只有相邻的重复项才会去重,因此在去重的时候最好先排序。bash
[root@localhost ~]# sort 2.txt |uniq 111 1111 2222 3333 4 5 [root@localhost ~]# sort 2.txt |uniq -c 1 111 3 1111 3 2222 3 3333 1 4 1 5 [root@localhost ~]#
[root@localhost ~]# sort 2.txt |uniq -c |tee a.txt 1 111 3 1111 3 2222 3 3333 1 4 1 5 [root@localhost ~]# cat a.txt 1 111 3 1111 3 2222 3 3333 1 4 1 5
[root@localhost ~]# echo "aminglinux" |tr 'a' 'A' Aminglinux [root@localhost ~]# echo "aminglinux" |tr '[anx]' '[ANX]' AmiNgliNuX [root@localhost ~]# echo "aminglinux" |tr '[a-z]' '[A-Z]' AMINGLINUX
[root@localhost ~]# find /etc/ -type f -name "*conf" -exec cat {} >> aa.txt \; [root@localhost ~]# du -sh aa.txt 160K aa.txt
[root@localhost ~]# split -b 1000 aa.txt [root@localhost ~]# ls 1.txt xab xah xan xat xaz xbf xbl xbr xbx xcd xcj xcp xcv xdb xdh xdn xdt xdz xef xel xer xex xfd xfj xfp xfv xgb 2.txt xac xai xao xau xba xbg xbm xbs xby xce xck xcq xcw xdc xdi xdo xdu xea xeg xem xes xey xfe xfk xfq xfw xgc aa.txt xad xaj xap xav xbb xbh xbn xbt xbz xcf xcl xcr xcx xdd xdj xdp xdv xeb xeh xen xet xez xff xfl xfr xfx xgd anaconda-ks.cfg xae xak xaq xaw xbc xbi xbo xbu xca xcg xcm xcs xcy xde xdk xdq xdw xec xei xeo xeu xfa xfg xfm xfs xfy a.txt xaf xal xar xax xbd xbj xbp xbv xcb xch xcn xct xcz xdf xdl xdr xdx xed xej xep xev xfb xfh xfn xft xfz xaa xag xam xas xay xbe xbk xbq xbw xcc xci xco xcu xda xdg xdm xds xdy xee xek xeq xew xfc xfi
[root@localhost ~]# split -b 1000 aa.txt aaa. [root@localhost ~]# ls 1.txt aaa.ai aaa.as aaa.bc aaa.bm aaa.bw aaa.cg aaa.cq aaa.da aaa.dk aaa.du aaa.ee aaa.eo aaa.ey aaa.fi aaa.fs aaa.gc 2.txt aaa.aj aaa.at aaa.bd aaa.bn aaa.bx aaa.ch aaa.cr aaa.db aaa.dl aaa.dv aaa.ef aaa.ep aaa.ez aaa.fj aaa.ft aaa.gd aaa.aa aaa.ak aaa.au aaa.be aaa.bo aaa.by aaa.ci aaa.cs aaa.dc aaa.dm aaa.dw aaa.eg aaa.eq aaa.fa aaa.fk aaa.fu aa.txt aaa.ab aaa.al aaa.av aaa.bf aaa.bp aaa.bz aaa.cj aaa.ct aaa.dd aaa.dn aaa.dx aaa.eh aaa.er aaa.fb aaa.fl aaa.fv anaconda-ks.cfg aaa.ac aaa.am aaa.aw aaa.bg aaa.bq aaa.ca aaa.ck aaa.cu aaa.de aaa.do aaa.dy aaa.ei aaa.es aaa.fc aaa.fm aaa.fw a.txt aaa.ad aaa.an aaa.ax aaa.bh aaa.br aaa.cb aaa.cl aaa.cv aaa.df aaa.dp aaa.dz aaa.ej aaa.et aaa.fd aaa.fn aaa.fx aaa.ae aaa.ao aaa.ay aaa.bi aaa.bs aaa.cc aaa.cm aaa.cw aaa.dg aaa.dq aaa.ea aaa.ek aaa.eu aaa.fe aaa.fo aaa.fy aaa.af aaa.ap aaa.az aaa.bj aaa.bt aaa.cd aaa.cn aaa.cx aaa.dh aaa.dr aaa.eb aaa.el aaa.ev aaa.ff aaa.fp aaa.fz aaa.ag aaa.aq aaa.ba aaa.bk aaa.bu aaa.ce aaa.co aaa.cy aaa.di aaa.ds aaa.ec aaa.em aaa.ew aaa.fg aaa.fq aaa.ga aaa.ah aaa.ar aaa.bb aaa.bl aaa.bv aaa.cf aaa.cp aaa.cz aaa.dj aaa.dt aaa.ed aaa.en aaa.ex aaa.fh aaa.fr aaa.gb
[root@localhost ~]# ls 1a.txt || wc -l 1.txt ls: 没法访问1a.txt: 没有那个文件或目录 25 1.txt [root@localhost ~]# ls 1.txt || wc -l 1.txt 1.txt
[root@localhost ~]# ls 1.txt && wc -l 1.txt 1.txt 25 1.txt [root@localhost ~]# ls 1a.txt && wc -l 1.txt ls: 没法访问1a.txt: 没有那个文件或目录
关于PROMPT_COMMAND环境变量的含义 http://www.linuxnote.org/prompt_command-environment-variables.html学习
source exec 区别 http://alsww.blog.51cto.com/2001924/1113112ui
Linux特殊符号大全 http://ask.apelearn.com/question/7720.net
sort并未按ASCII排序 http://blog.csdn.net/zenghui08/article/details/7938975code
Linux 系统添加操做记录审计 http://www.68idc.cn/help/server/linux/2014042190951.htmlserver