目錄
- locate
- which
- whereis
- grep
locate
解釋
命令名稱:locate
命令所在路徑:/usr/bin/locate
執行權限:所有用戶
功能描述:在檔案資料庫中查找檔案
語法
locate [檔案]
-i 不區分大小寫
提示locate命令找不到
yum -y install mlocate
updatedb
locate缺陷
1.locate不是實時的,新建的檔案可能找不到,需要手動運行命令更新updatedb
2.locate無法查找/tmp檔案夾下的內容,因為/tmp是臨時檔案夾,updatedb也不管用
示例
# 搜索檔案(區分大小寫)
locate test.txt
# 手動更新檔案資料庫
updatedb
# 搜索檔案(不區分大小寫)
locate -i test.txt
which
解釋
命令名稱:which
命令所在路徑:/usr/bin/which
執行權限:所有用戶
功能描述:搜索命令所在目錄及別名資訊
語法
which ls
示例
# 查找cp命令所在的目錄及別名
which cp
[root@izm5e2q95pbpe1hh0kkwoiz ~]# which cp
alias cp='cp -i'
/usr/bin/cp
# cp的是cp -i的別名
# cp命令的目錄是/usr/bin/cp
[root@izm5e2q95pbpe1hh0kkwoiz ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
whereis
解釋
命令名稱:whereis
命令所在路徑:/usr/bin/whereis
執行權限:所有用戶
功能描述:搜索命令所在目錄及幫助檔案路徑
語法
whereis ls
示例
# 查找ls命令所在的目錄及幫助檔案路徑
whereis ls
[root@izm5e2q95pbpe1hh0kkwoiz ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
# ls命令所在路徑為/usr/bin/ls
# ls幫助檔案的路徑為/usr/share/man/man1/ls.1.gz
grep
解釋
命令名稱:grep
命令所在路徑:/bin/grep
執行權限:所有用戶
功能描述:在檔案中搜尋字串匹配的行并輸出
語法
grep -v [指定字串] [檔案]
-i 不區分大小寫(insensitive)
-v 排除指定字串
示例
# 查找target在/etc/inittab檔案中(區分大小寫)
grep target /etc/inittab
[root@izm5e2q95pbpe1hh0kkwoiz ~]# grep target /etc/inittab
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
# To view current default target, run:
# To set a default target, run:
# systemctl set-default TARGET.target
## 查找target在/etc/inittab檔案中(不區分大小寫)
grep -i target /etc/inittab
## 在/etc/inittab檔案中排除以#號開頭的所有行
grep -v ^# /etc/inittab
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/137645.html
標籤:Linux
上一篇:linux中find檔案搜索命令
下一篇:linux中vim常用操作
