4.Linux文件查找工具。 Linux經常使用locate與find作為文件查找命令。find可以認為是系統自帶的命令,功能也挺多但是使用方法相對有點繁瑣。find查找的是實時文件數據,一般用於查詢明確知道文件目錄及文件名的時候,可以按照參數將查詢出來的文件做進一步操作如:列印、刪除、執行命令等。 ...
4.Linux文件查找工具。
Linux經常使用locate與find作為文件查找命令。find可以認為是系統自帶的命令,功能也挺多但是使用方法相對有點繁瑣。find查找的是實時文件數據,一般用於查詢明確知道文件目錄及文件名的時候,可以按照參數將查詢出來的文件做進一步操作如:列印、刪除、執行命令等。find命令對使用者的要求比較高,要相當熟練的操作,但是功能相對豐富。
相對於find命令locate命令就比較簡單而且效率比較快,因為locate命令安裝時會創建一個檔案資料庫,裡面記錄了當前文件系統的文件數據,locate命令查找的就是這個資料庫中的數據所以效率相對find命令會比較高。缺點就是因為資料庫中的數據不會實時更新,如果最近修改了文件名那麼可能使用該命令就會搜索不到文件。要更新資料庫需要執行updatedb命令執行locate資料庫。一般在crontab定時任務中會加入一個定時任務每天跑一次updatedb,這個動作一般都會在命令安裝的時候自動設置一次(未經確認,請自行研究)。另外一個比較耐用的功能就是locate預設是模糊查找的哦,所以這裡選擇安裝locate命令作為查找工具
root@454009d432a4:/# apt-cache search locate //搜索locate安裝包 mlocate - quickly find files on the filesystem based on their name //我們要安裝的資源 dlocate - fast alternative to dpkg -L and dpkg -S gameconqueror - locate and modify a variable in a running process (GUI) libcommons-discovery-java - locates classes that implement a given Java interfac e libcommons-discovery-java-doc - locates classes that implement a given Java inte rface (documentation)
...
...
...
root@454009d432a4:/# apt-get install mlocate //安裝資源
...
...
...
root@454009d432a4:/# locate -h //命令說明
Usage: locate [OPTION]... [PATTERN]...
Search for entries in a mlocate database.
-A, --all only print entries that match all patterns
-b, --basename match only the base name of path names
-c, --count only print number of found entries
-d, --database DBPATH use DBPATH instead of default database (which is
/var/lib/mlocate/mlocate.db)
-e, --existing only print entries for currently existing files
-L, --follow follow trailing symbolic links when checking file
existence (default)
-h, --help print this help
-i, --ignore-case ignore case distinctions when matching patterns
-p, --ignore-spaces ignore punctuation and spaces when matching patterns
-t, --transliterate ignore accents using iconv transliteration when
matching patterns
-l, --limit, -n LIMIT limit output (or counting) to LIMIT entries
-m, --mmap ignored, for backward compatibility
-P, --nofollow, -H don't follow trailing symbolic links when checking file
existence
-0, --null separate entries with NUL on output
-S, --statistics don't search for entries, print statistics about each
used database
-q, --quiet report no error messages about reading databases
-r, --regexp REGEXP search for basic regexp REGEXP instead of patterns
--regex patterns are extended regexps
-s, --stdio ignored, for backward compatibility
-V, --version print version information
-w, --wholename match whole path name (default)
root@454009d432a4:/# locate cron //查找cron相關的文件
/etc/cron.d
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
/etc/crontab
/etc/cron.d/.placeholder
/etc/cron.daily/.placeholder
/etc/cron.daily/apt-compat
/etc/cron.daily/dpkg
/etc/cron.daily/mlocate //安裝mlocate資源時預設添加的每天定時任務
...
...
...
更詳細的命令說明參考下麵鏈接
資料來源鏈接:https://blog.csdn.net/looper66/article/details/55254682
5.Linux管道命令“|”
管道命令是命令模式下非常好用的技術,是一種將命令的結果作為其他命令的輸入信息的技術。
該命令只能將命令的正確結果輸出傳遞給下一個命令作為輸入,如果命令報錯則不能傳遞給下個命令
舉例:
//正常的結果
root@454009d432a4:/# apt-cache search make | more //將apt-cache search make 命令的輸出結果作為more命令的輸入信息,因為more命令有分頁輸出的效果所以就形成了分頁輸出搜索結果的效果
cmake-extras - Extra CMake utility modules
cmake-fedora - Set of scripts and cmake modules that simplify the release proces
s
cmake-qt-gui - Qt based user interface for CMake (cmake-gui)
colormake - simple wrapper around make to colorize output
colortail - log colorizer that makes log checking easier
--More--
//錯誤的結果
root@454009d432a4:/# 66666 | apt-cache search //如果66666不是一個正確的命令所以apt-cache search沒有輸入,這時候相當於兩個命令都會報錯
bash: 66666: command not found //66666的錯誤提示
E: You must give at least one search pattern //apt-cache search的錯誤提示
資料鏈接:https://blog.csdn.net/wirelessqa/article/details/8968381
6.Linux命令輸出重定向“>”、“>>”
管道命令的概念其實跟 “>”與“>>”符號的概念非常像。只不過“>”與“>>”符號一般只作用於文件而不是命令。
以下將“>”與“>>”暫且稱為輸出重定向符號。輸出重定向符號的作用是將命令的正確輸出重定向到指定文件中(即寫入到指定文件中),如果文件不存在則新增文件。“>”,“>>”區別在於“>”是將文件中的內容覆蓋為輸出內容,“>>”是在文件後面追加輸出內容。例如:
root@454009d432a4:/# apt-cache search net-tools >> workdir/check.log //將apt-cache search net-tools的結果寫入workdir/check.log文件中,如果文件不存在自動創建文件
root@454009d432a4:/# apt-cache search net-tools > workdir/check.log //將apt-cache search net-tools的結果覆蓋workdir/check.log文件中的內容,如果文件不存在自動創建文件
資料鏈接:https://blog.csdn.net/qq_36076233/article/details/69061684