From ff38fb0b61f820ab6115c91ded0f0599f120fbf2 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Thu, 24 Jun 2021 11:01:59 +0800 Subject: [PATCH] TSL&PRF --- .../20210623 Replace find with fd on Linux.md | 75 ++++++++----------- 1 file changed, 33 insertions(+), 42 deletions(-) rename {sources => translated}/tech/20210623 Replace find with fd on Linux.md (50%) diff --git a/sources/tech/20210623 Replace find with fd on Linux.md b/translated/tech/20210623 Replace find with fd on Linux.md similarity index 50% rename from sources/tech/20210623 Replace find with fd on Linux.md rename to translated/tech/20210623 Replace find with fd on Linux.md index 2a62cda9aa..9daf85b38c 100644 --- a/sources/tech/20210623 Replace find with fd on Linux.md +++ b/translated/tech/20210623 Replace find with fd on Linux.md @@ -3,42 +3,40 @@ [#]: author: (Sudeshna Sur https://opensource.com/users/sudeshna-sur) [#]: collector: (lujun9972) [#]: translator: (wxy) -[#]: reviewer: ( ) +[#]: reviewer: (wxy) [#]: publisher: ( ) [#]: url: ( ) -Replace find with fd on Linux +在 Linux 上用 fd 代替 find ====== -The fd command is a popular, user-friendly alternative to the find -command. -![Magnifying glass on code][1] -Many Linux programmers use the `find` command every single day of their career. But `find` gives a limited set of filesystem entries, and if you have to do a large set of `find` operations, it's not even very fast. So instead, I prefer to use the Rust `fd` command because it provides sensible defaults that work for most use cases. +> fd 命令是一个流行的、用户友好的 find 命令的替代品。 -As its [README][2] says, "`fd` is a program to find entries in your filesystem. It is a simple, fast, and user-friendly alternative to `find`." It features parallelized directory traversal, so it can search multiple directories at once. It supports regular expressions (regex) and glob-based patterns. +![代码上的放大镜][1] -### Install fd +许多 Linux 程序员在其工作中每天都在使用 `find` 命令。但是 `find` 给出的文件系统条目是有限的,如果你要进行大量的 `find` 操作,它甚至不是很快速。因此,我更喜欢使用 Rust 编写的 `fd` 命令,因为它提供了合理的默认值,适用于大多数使用情况。 -On Linux, you can install `fd` from your software repository (a list of available packages can be found on the [fd page on Repology][3].) For example, on Fedora: +正如它的 [README][2] 所说,“`fd` 是一个在文件系统中寻找条目的程序。它是一个简单、快速和用户友好的 `find` 的替代品。”它的特点是目录的并行遍历,可以一次搜索多个目录。它支持正则表达式(regex)和基于通配符的模式。 +### 安装 fd + +在 Linux 上,你可以从你的软件库中安装 `fd`(可用的软件包列表可以在 [Repology 上的 fd 页面][3] 找到)。 例如,在 Fedora 上: ``` -`$ sudo dnf install fd-find` +$ sudo dnf install fd-find ``` -On macOS, use [MacPorts][4] or [Homebrew][5]. - -Alternately, you can use Rust's Cargo package manager: +在 macOS 上,可以使用 [MacPorts][4] 或 [Homebrew][5]。 +另外,你也可以使用 Rust 的 Cargo 软件包管理器: ``` -`$ cargo install fd-find` +$ cargo install fd-find ``` -### Use fd - -To do a simple search, run `fd` after any argument, such as: +### 使用 fd +要做一个简单的搜索,运行 `fd` 并在后面跟上要搜索的名字,例如: ``` $ fd sh @@ -59,8 +57,7 @@ registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.12.19+1.1.0/libgit2/src/c [...] ``` -If you want to search for a specific directory, provide the directory path as a second argument to `fd`, such as: - +如果你想搜索一个特定的目录,可以将目录路径作为 `fd` 的第二个参数,例如: ``` $ fd passwd /etc @@ -70,8 +67,7 @@ $ fd passwd /etc /etc/security/opasswd ``` -To search for a particular file extension, use `-e` as an option. For example: - +要搜索一个特定的文件扩展名,使用 `-e` 作为选项。例如: ``` $ fd . '/home/ssur/exa' -e md @@ -83,22 +79,18 @@ $ fd . '/home/ssur/exa' -e md $ ``` -You can also execute a command by providing `-x` or `-X`. +你也可以通过提供 `-x` 或 `-X` 来执行一个命令。 - * The `-x/--exec` option runs an external command for each search result (in parallel). - * The `-X/--exec-batch` option launches the external command once with all search results as arguments. - - - -For example, to recursively find all ZIP archives and unpack them: + * `-x`/`--exec`:选项为每个搜索结果(并行)运行一个外部命令。 + * `-X`/`--exec-batch`:选项将所有搜索结果作为参数启动一次外部命令。 +例如,要递归地找到所有的 ZIP 档案并解压: ``` -`$ fd -e zip -x unzip` +$ fd -e zip -x unzip ``` -Or, to list all files under a particular directory that were changed within the last _n_ number of days, use the `--changed-within` option: - +或者,要列出某个特定目录下在过去 _n_ 天内改变的所有文件,使用`--changed-within` 选项: ``` $ fd . '/home/ssur/Work/' --changed-within 10d @@ -107,24 +99,23 @@ $ fd . '/home/ssur/Work/' --changed-within 10d [...] ``` -And to search all files that were changed before a specific number of days, use the `--changed-before` _n_ option: - +而要搜索所有在特定天数之前被修改的文件,请使用 `--changed-before` _n_ 选项: ``` -`$ fd . '/home/ssur/Work/' --changed-before 365d` +$ fd . '/home/ssur/Work/' --changed-before 365d ``` -Here, `.` acts as a wildcard entry to instruct `fd` to return all files. +这里,`.` 作为一个(正则)通配符,指示 `fd` 返回所有文件。 -To learn about more the functionalities of `fd`, consult its [documentation][2] on GitHub. +要了解更多关于 `fd` 的功能,请查阅 GitHub 上的 [文档][2]。 -### Conclusion +### 总结 -One thing I especially like about `fd` is that the search pattern is case-insensitive by default, which makes it easier to find things even when you have imprecise knowledge about what you're looking for. Better yet, it _automatically_ switches to case-sensitive if the pattern contains an uppercase character. +我特别喜欢 `fd` 的一点是,搜索模式默认是不区分大小写的,这使得它更容易找到东西,即使你对你要找的东西没有精确的认识。更好的是,如果模式包含一个大写的字符,它就会*自动*切换到大小写敏感。 -Another benefit is that it uses color-coding to highlight different file types. +另一个好处是,它使用颜色编码来突出不同的文件类型。 -If you are already using this amazing Rust tool, please let us know your thoughts in the comments. +如果你已经在使用这个神奇的 Rust 工具,请在评论中告诉我们你的想法。 -------------------------------------------------------------------------------- @@ -132,8 +123,8 @@ via: https://opensource.com/article/21/6/fd-linux 作者:[Sudeshna Sur][a] 选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) +译者:[wxy](https://github.com/wxy) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出