FD

linux tools fd

Alternative to Find Command

(and it's really good !)

https://github.com/sharkdp/fd

Installation

You can install on Debian/Ubuntu os with:

 $ apt-get install fd

or

 $ apt-get install fd-find
 or  
 Go to  [https://github.com/sharkdp/fd/releases](https://github.com/sharkdp/fd/releases) and take the good version for you EG:
 $ wget https://github.com/sharkdp/fd/releases/download/v7.5.0/fd_7.5.0_amd64.deb
 $ dpkg -i fd_7.5.0_amd64.deb

fd is designed to find entries in your filesystem. The most basic search you can perform is to run fd with a single argument: the search pattern.

For example, assume that you want to find an old script of yours (the name included netflix):

$ fd netfl     
$ Software/python/imdb-ratings/netflix-details.py

If called with just a single argument like this, fd searches the current directory recursively for any entries that contain the pattern netfl.

The search pattern is treated as a regular expression. Here, we search for entries that start with x and end with rc:

$ cd /etc
$ fd '^x.*rc$'
$ X11/xinit/xinitrc
$ X11/xinit/xserverrc

Specifying the root directory

If we want to search a specific directory, it can be given as a second argument to fd:

$ fd passwd /etc
$ /etc/default/passwd
$ /etc/pam.d/passwd
$ /etc/passwd

Running fd without any arguments

fd can be called with no arguments. This is very useful to get a quick overview of all entries in the current directory, recursively (similar to ls -R):

$ cd fd/tests
$ fd
$ testenv
$ testenv/mod.rs
$ tests.rs

If you want to use this functionality to list all files in a given directory, you have to use a catch-all pattern such as . or ^:

$ fd . fd/tests/
$ testenv
$ testenv/mod.rs
$ tests.rs

Searching for a particular file extension

Often, we are interested in all files of a particular type. This can be done with the -e (or --extension) option. Here, we search for all Markdown files in the fd repository:

$ cd fd
$ fd -e md
$ CONTRIBUTING.md
$ README.md

The -e option can be used in combination with a search pattern:

$ fd -e rs mod
$ src/fshelper/mod.rs
$ src/lscolors/mod.rs
$ tests/testenv/mod.rs

Hidden and ignored files

By default, fd does not search hidden directories and does not show hidden files in the search results. To disable this behavior, we can use the -H (or --hidden) option:

$ fd pre-commit
$ fd -H pre-commit
$ .git/hooks/pre-commit.sample

If we work in a directory that is a Git repository (or includes Git repositories), fd does not search folders (and does not show files) that match one of the .gitignore patterns.

To disable this behavior, we can use the -I (or --no-ignore) option:

$ fd num_cpu
$ fd -I num_cpu
$ target/debug/deps/libnum_cpus-f5ce7ef99006aa05.rlib

To really search all files and directories, simply combine the hidden and ignore features to show everything (-HI).

Excluding specific files or directories

Sometimes we want to ignore search results from a specific subdirectory.

For example, we might want to search all hidden files and directories (-H) but exclude all matches from .git directories. We can use the -E (or --exclude) option for this. It takes an arbitrary glob pattern as an argument:

$ fd -H -E .git …

We can also use this to skip mounted directories: $ fd -E /mnt/external-drive … .. or to skip certain file types: $ fd -E '*.bak' …

To make exclude-patterns like these permanent, you can create a .fdignore file. They work like .gitignore files, but are specific to fd. For example:

$ cat ~/.fdignore
$ /mnt/external-drive
$ *.bak

Note: fd also supports .ignore files that are used by other programs such as rg or ag. Using fd with xargs or parallel

If we want to run a command on all search results, we can pipe the output to xargs:

$ fd -0 -e rs | xargs -0 wc -l

Here, the -0 option tells fd to separate search results by the NULL character (instead of newlines). In the same way, the -0 option of xargs tells it to read the input in this way. Deleting files

You can use fd to remove all files and directories that are matched by your search pattern. If you only want to remove files, you can use the --exec-batch/-X option to call rm.

For example, to recursively remove all .DS_Store files, run:

$ fd -H '^\.DS_Store$' -tf -X rm

Next Post