四剑客第三关
1 find使用方法:
根据文件大小查找 命令:
根据文件权限查找数据 :
find /etc/passwd -type f -size +10M
find /etc/passwd -perm 755
[root@master ~]# find /etc/passwd -type f -size +10M
[root@master ~]# find /etc/passwd -perm 7552 把 abc压缩成格式如 2020-09-29.abc.tar.gz
tar -zcf "$(date +%Y-%m-%d).abc.tar.gz" abc
[root@master ~]# cat abc
dshjfgsd
sdkfhksdf
sdkfgsdf
flksehfhes
sakhjfasjghdfas
fjnksdfsdjf
sdfjkhsdjfse
sajkefhjsegf
wenrjeshfukse
wejnrkhefghwe
rasejghfujiwebf
'fsebjfhse
ejkrgsefhe
sekfbegfe
askefseuifbwejfsekjtg
wjkerusegufhbse
sejnkrghsehjfge
tnwejfhwejfbwe
asnjefghesjkf
se'e,k
ejkrgseuiuhe
enrjsehfwe
awejkfjiwehf
sejkhrsehfw
'arnweh
serheuishfuihwe
[root@master ~]# tar -zcf "$(date +%Y-%m-%d).abc.tar.gz" abc
[root@master ~]# ls
10.txt 14.txt 18.txt 20.txt 3.txt 7.txt anaconda-ks.cfg nwq1.6.sh
11.txt 15.txt 19.txt 21.txt 4.txt 8.txt CentOS6-Base-163.repo profile
12.txt 16.txt 1.txt 22.txt 5.txt 9.txt hosts
13.txt 17.txt 2024-03-14.abc.tar.gz 2.txt 6.txt abc motd3 解压如上文件
tar -xzf "2020=09-29.abc.tar.gz"
tar -xzf "2024-03-14.abc.tar.gz" -C /test 解压到目录
[root@master ~]# tar -xzf "2024-03-14.abc.tar.gz" -C /test
[root@master ~]# cd /test
[root@master test]# ls
abc
[root@master test]# cat abc
dshjfgsd
sdkfhksdf
sdkfgsdf
flksehfhes
sakhjfasjghdfas
fjnksdfsdjf
sdfjkhsdjfse
sajkefhjsegf
wenrjeshfukse
wejnrkhefghwe
rasejghfujiwebf
'fsebjfhse
ejkrgsefhe
sekfbegfe
askefseuifbwejfsekjtg
wjkerusegufhbse
sejnkrghsehjfge
tnwejfhwejfbwe
asnjefghesjkf
se'e,k
ejkrgseuiuhe
enrjsehfwe
awejkfjiwehf
sejkhrsehfw
'arnweh
serheuishfuihwe4 美元符号:$ 表达什么:
!作用:
| 作用:
xargs作用:
$ 引用变量或命令替换
! 执行历史记录或逻辑非操作 通常与[]结合使用
| 前一个命令的输出作为后一个命令的输入5 查找指定数据信息进行复制 查找出.txt文件,批量复制到/tmp目录
find . -name "*.txt" |xargs cp -t /tmp
或者
find . -name "*.txt" -exec cp {} /tmp \;
[root@master ~]# touch {1..22}.txt
[root@master ~]# ls
10.txt 13.txt 16.txt 19.txt 21.txt 3.txt 6.txt 9.txt hosts profile
11.txt 14.txt 17.txt 1.txt 22.txt 4.txt 7.txt anaconda-ks.cfg motd
12.txt 15.txt 18.txt 20.txt 2.txt 5.txt 8.txt CentOS6-Base-163.repo nwq1.6.sh
[root@master ~]# find . -name "*.txt" -exec cp {} /tmp \;
[root@master ~]# ls
10.txt 13.txt 16.txt 19.txt 21.txt 3.txt 6.txt 9.txt hosts profile
11.txt 14.txt 17.txt 1.txt 22.txt 4.txt 7.txt anaconda-ks.cfg motd
12.txt 15.txt 18.txt 20.txt 2.txt 5.txt 8.txt CentOS6-Base-163.repo nwq1.6.sh
[root@master ~]# cd /tmp
[root@master tmp]# ls
10.txt 14.txt 18.txt 21.txt 4.txt 8.txt yum_save_tx.2024-03-09.20-43.MjeG_P.yumtx
11.txt 15.txt 19.txt 22.txt 5.txt 9.txt
12.txt 16.txt 1.txt 2.txt 6.txt test01.txt
13.txt 17.txt 20.txt 3.txt 7.txt test.txt6 查找指定数据信息进行移动 查找出*.txt文件,批量移动到/tmp目录
find . -name "*.txt" -exec mv {} /tmp \;
[root@master ~]# touch {1..20}.txt
[root@master ~]# ls
10.txt 13.txt 16.txt 19.txt 2.txt 5.txt 8.txt CentOS6-Base-163.repo nwq1.6.sh test.txt
11.txt 14.txt 17.txt 1.txt 3.txt 6.txt 9.txt hosts profile
12.txt 15.txt 18.txt 20.txt 4.txt 7.txt anaconda-ks.cfg motd test01.txt
[root@master ~]# find . -name "*.txt"
./1.txt
./test.txt
./test01.txt
./2.txt
./3.txt
./4.txt
./5.txt
./6.txt
./7.txt
./8.txt
./9.txt
./10.txt
./11.txt
./12.txt
./13.txt
./14.txt
./15.txt
./16.txt
./17.txt
./18.txt
./19.txt
./20.txt
[root@master ~]# find . -name "*.txt" -exec mv {} /tmp \;
[root@master ~]# cd /tmp
[root@master tmp]# ls
10.txt 13.txt 16.txt 19.txt 2.txt 5.txt 8.txt test.txt
11.txt 14.txt 17.txt 1.txt 3.txt 6.txt 9.txt yum_save_tx.2024-03-09.20-43.MjeG_P.yumtx
12.txt 15.txt 18.txt 20.txt 4.txt 7.txt test01.txt7 将以abc开头的行找出来?
语法 grep "^abc" 文件名
grep "^abc" /etc/passwd
[root@master ~]# cat test01.txt
sdjfgs
sdjkhfjksdhf
sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi
efjhehew
rjkthrkhgwe
eklrhteh
etwehut
ethkeht
ejkfekhre
ehrkefie
nrekwhwet
ekhke
ektheh
[root@master ~]# grep '^abc' test01.txt
abcehiehkheke
abcehiiegbwejthiehi8 将以linux结尾的行找出来?
grep 'linux$' 文件名
[root@master ~]# cat test01.txt
sdjfgs
sdjkhfjksdhf
sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi
efjhehew
rjkthrkhgwe
eklrhteh
etwehut
ethkeht
ejkfekhre
ehrkefie
nrekwhwet
ekhke
ektheh
[root@master ~]# grep 'linux' test01.txt
linux fsdhfsdfjsfhshdfslinux9 将全部内容显示,但不要显示空行
grep -v '^$' 文件名
[root@master ~]# cat test01.txt
sdjfgs
sdjkhfjksdhf
sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi
efjhehew
rjkthrkhgwe
eklrhteh
etwehut
ethkeht
ejkfekhre
ehrkefie
nrekwhwet
ekhke
ektheh
[root@master ~]# grep -v '^$' test01.txt
sdjfgs
sdjkhfjksdhf
sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi
efjhehew
rjkthrkhgwe
eklrhteh
etwehut
ethkeht
ejkfekhre
ehrkefie
nrekwhwet
ekhke
ektheh10 利用linux什么命令真正统计目录的大小?
du -sh /etc/passwd
[root@master ~]# du -sh /etc/passwd
8.0K /etc/passwd










