一. find命令:
warning警告
-maxdepth 這個參數(shù)要放在其他參數(shù)之前。
[root@oldboyedu59 ~]# find / -type d -maxdepth 1
find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
/
/boot
/dev
/proc
/run
/sys
/etc
/root
/var
/tmp
/usr
/home
/media
/mnt
/opt
/srv
/old
/oldboy
/lidao
/oldwang
/newwang
/data
/tmp01
[root@oldboyedu59 ~]#
[root@oldboyedu59 ~]# find / -maxdepth 1 -type d
/
/boot
/dev
/proc
/run
/sys
/etc
/root
/var
/tmp
/usr
/home
/media
/mnt
/opt
/srv
/old
/oldboy
/lidao
/oldwang
/newwang
/data
/tmp01
參數(shù)書寫錯誤
Expected a positive decimal integer argument to -maxdepth, but got ‘-type’
發(fā)現(xiàn)了一個-maxdepth這個參數(shù)后面應(yīng)該加上數(shù)字翅雏,但是卻找到了-type
[root@oldboyedu59 ~]# find /etc/ -maxdepth -type f -iname "*.conf"
find: Expected a positive decimal integer argument to -maxdepth, but got ‘-type’
參數(shù)書寫錯誤
Arguments to -type should contain only one letter
-type的參數(shù) 應(yīng)該只是一個字母
[root@oldboyedu59 ~]# find /etc/ -maxdepth 1 -type -iname "*.conf"
find: Arguments to -type should contain only one letter
Invalid argument 無效的參數(shù)
不支持小數(shù)难礼,使用整數(shù)
[root@oldboy001 ~]# find /tmp/ -size -0.5k
find: Invalid argument `-0.5k' to -size
will not overwrite just-created
不會覆蓋剛剛創(chuàng)建的文件
不同目錄下可能有相同的文件
模擬錯誤:
[root@oldboyedu59 ~]# touch /oldboy/oldboy.txt /oldboy/lidao/oldboy.txt
[root@oldboyedu59 ~]# find /oldboy/ -name 'oldboy.txt'
/oldboy/lidao/oldboy.txt
/oldboy/oldboy.txt
[root@oldboyedu59 ~]# find /oldboy/ -name 'oldboy.txt' |xargs cp -t /tmp
cp: will not overwrite just-created ‘/tmp/oldboy.txt’ with ‘/oldboy/oldboy.txt’
[root@oldboyedu59 ~]# find /etc/ -type f -name "*.conf" |xargs cp -t /tmp/
cp: will not overwrite just-created ‘/tmp/system.conf’ with ‘/etc/dbus-1/system.conf’
cp: will not overwrite just-created ‘/tmp/wpa_supplicant.conf’ with ‘/etc/wpa_supplicant/wpa_supplicant.conf’
二. 正則表達(dá)式部分
1.正則-中括號里面的 ,逗號
grep '[a-zA-Z]' oldboy.txt
grep '[a-z,A-Z]' oldboy.txt
2.正則表達(dá)式中括號 [] 里面寫入什么(除了第1位的^)就匹配什么
[root@oldboyedu59 /oldboy]# cat oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our size is http://blog.oldboyedu.com
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
\\\\\...???$$$$^^&^
[root@oldboyedu59 /oldboy]# grep '[mn\.]' oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our size is http://blog.oldboyedu.com
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
\\\\\...???$$$$^^&^
3.
grep '^[mon][mo.]$' /tmp/oldboy
每一行只有2個字符
4. [^m^n^o] 神馬意思夭问?
grep '[^m^n^o]' oldboy.txt
[^]表示取反 但是^必須在中括號里面的第1個位置
'[mn^o]' 表示排除m或n或o或^(尖號)
[root@oldboyedu59 /oldboy]# cat oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our size is http://blog.oldboyedu.com
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
\\\\\...???$$$$^^&^
[root@oldboyedu59 /oldboy]# grep '[^m^n^o]' oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our size is http://blog.oldboyedu.com
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
\\\\\...???$$$$^^&^
5.[^abc] vs grep -v
名稱 | 含義 |
---|---|
[^abc] | 字符 不要a或b或c |
grep -v | 行 排除某一行 |
[root@oldboyedu59 /oldboy]# grep -v 'oldboy' oldboy.txt
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
\\\\\...???$$$$^^&^
[root@oldboyedu59 /oldboy]# grep '[^a-Z]' oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our size is http://blog.oldboyedu.com
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
\\\\\...???$$$$^^&^
6.[abc] vs a|b|c
名稱 | 含義 |
---|---|
[abc] | 表示字符的或者 匹配a或b或c |
a|b|c | 表示字母也可以表示單詞oldboy|oldgirl |
7.grep '[^$]' oldboy.txt
grep '[^$]' oldboy.txt
三.sed命令錯誤集合
invalid usage of line address 0
無效的行號
[root@oldboyedu59 /oldboy]# sed -n '0,5p' lidao.txt
sed: -e expression #1, char 4: invalid usage of line address 0
Unmatched
不成對的 ( (小括號)
[root@oldboyedu59 ~]# stat /etc/hosts |sed -n 4p |sed -r 's#^.*(0##g'
sed: -e expression #1, char 10: Unmatched ( or \(
stat /etc/hosts |sed -n 4p |sed -r 's#(^.*0)(.*)(/-.*$)#\2#g'
老師,這個第一個括號里的(^.*)為啥沒有貪婪性
四.三劍客awk錯誤集合
awk
1. awk: cmd. line:1: fatal: division by zero attempted
[root@web01 ~]# x=10
[root@web01 ~]# y=3
[root@web01 ~]# awk 'BEGIN{print $x/$y}'
awk: cmd. line:1: fatal: division by zero attempted
[root@web01 ~]# #-v 創(chuàng)建或修改awk變量
[root@web01 ~]# awk -vn1=10 -vn2=3 'BEGIN{print n1/n2}'
3.33333
[root@web01 ~]# awk -vn1=$x -vn2=$y 'BEGIN{print n1/n2}'
3.33333
[root@web01 ~]#
2. awk: cmd. line:1: (FILENAME=- FNR=1) fatal: attempt to access field -1
[root@web01 ~]# echo {1..10..5}|awk '{print $(NF-3)}'
awk: cmd. line:1: (FILENAME=- FNR=1) fatal: attempt to access field -1
掃我入群:598972270