用 fd 替代 find
linux find shell -sudo apt install fd-find; ln -s $(which fdfind) ~/.local/bin/fd
Why
find 非常強大,前提是你會用。fd 更少的命令參數。
fd PATTERN === find -iname '*PATTERN*'
What
- fd
-
fd 基於
Rust的 Unix/Linux 命令find的替代品。-
內定是使用正則表示式(
Regular)。 -
內定忽略隱藏檔名。使用
-H搜尋隱藏檔。 -
內定依工作目錄中的
.gitignore忽略搜尋。使用-I忽略.gitignore。 -
若
PATTERN沒有大小寫則自動判斷為忽略大小寫。反之則區分大小寫。
-
How
Install
> sudo apt install fd-find;
> ln -s $(which fdfind) ~/.local/bin/fd
Alt
-
找當前目錄及其子目錄下的檔名。
find . -name '*mydoc*' ⇒ fd mydoc
fd 內定是使用正則表示式(Regular)。
-
搜尋指定目錄下的檔名
find /etc -name '*passwd*' ⇒ fd passwd /etc
-
列出目錄下所有檔案
find ~/ -type f =⇒ fd -H . ~/
fd 內定忽略隱藏檔名。使用 -H 搜尋隱藏檔。
-
只搜尋檔案名稱
find ./ -type f -name *log* ⇒ fd -tf log
-
只搜尋目錄名稱
find ./ -type d -name *log* ⇒ fd -td log
-
搜尋附檔名
find -name '.md' | grep readme ⇒ fd -e md readme
-
對找到的名稱作為參數執行命令
find ./ -type f -name '*.zip' | xargs -i unzip {} ⇒ fd -e zip -x unzip
-
忽略特定的子目錄
find . -path './.git' -prune -o -name 'config' -print ⇒ fd -H -E .git config
fd 使用 -E 排除路徑。