Updates for the tutorial
Before adoption: this commit came in with the history the project adopted, so no landing records it.
[skip ci]
authored by sharkdp · committed by David Peter · parent d32fe02 · Browse files · 1 file·+74 added−168 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+74 added−168 removed
- other:+74 added−168 removed
Provenance
- Commit
5863a5e- Tree
7b66b09- Author
sharkdp <davidpeter@web.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
d32fe02
1 file changed+74 added−168 removed
modified:README.md+74 added-168 removed
192 unmodified lines193 ```194 195 ## Tutorial196 197-First, to see all command line options, you can get `fd`'s help text by running:198-```199-fd --help200-```197+First, to get an overview of all available command line options, you can either run198+`fd -h` for a concise help message (see above) or `fd --help` for a more detailed199+version.200 202-`fd` can be called with no arguments, it'll then show the content of the actual directory203-recursively (like `ls -R`):204-```205-> cd fd206-> fd207-appveyor.yml208-build.rs209-Cargo.lock210-Cargo.toml211-LICENSE212-README.md213-src214-src/app.rs215-src/fshelper216-src/fshelper/mod.rs217-src/lscolors218-src/lscolors/mod.rs219-src/main.rs220-tests221-tests/testenv222-tests/testenv/mod.rs223-tests/tests.rs224-```201+### Simple search202 226-If we work in a directory that is a Git repository (or includes several Git repositories), `fd`227-does not search folders (and does not show files) that match the `.gitignore` pattern. For instance,228-see above example, and note that .gitignore is the following:203+*fd* is designed to find entries in your filesystem. The most basic search you can perform is to204+run *fd* with a single argument: the search pattern. For example, assume that you want to find an205+old script of yours (the name included `netflix`):206+``` bash207+> fd netfl208+Software/python/imdb-ratings/netflix-details.py209 ```230-target/231-**/*.rs.bk232-```210+If called with just a single argument like this, *fd* searches the current directory recursively211+for any entries that *contain* the pattern `netfl`.212 234-To disable this behavior, we can use the `-I` (or `--ignore`) option:235-```236-> fd -I237-Cargo.lock238-Cargo.toml239-LICENSE240-README.md241-appveyor.yml242-build.rs243-src244-src\app.rs245-src\fshelper246-src\fshelper\mod.rs247-src\lscolors248-src\lscolors\mod.rs249-src\main.rs250-target251-target\debug252-target\debug\build253-target\debug\build\fd-find-11fb469ceafee9ce254-target\debug\build\fd-find-11fb469ceafee9ce\out255-target\debug\build\fd-find-11fb469ceafee9ce\out\_fd256-target\debug\build\fd-find-11fb469ceafee9ce\out\_fd.ps1257-target\debug\build\fd-find-11fb469ceafee9ce\out\fd.bash-completion258-target\debug\build\fd-find-11fb469ceafee9ce\out\fd.fish259-target\debug\build\fd-find-11fb469ceafee9ce\output260-target\debug\build\fd-find-8682b98943903a5b261-target\debug\build\fd-find-8682b98943903a5b\build-script-build.exe262-target\debug\build\fd-find-8682b98943903a5b\build_script_build-8682b98943903a5b.exe263-target\debug\build\fd-find-8682b98943903a5b\build_script_build-8682b98943903a5b.pdb264-target\debug\build\kernel32-sys-7568a971f6718c45265-target\debug\build\kernel32-sys-7568a971f6718c45\out266-target\debug\build\kernel32-sys-7568a971f6718c45\output267-target\debug\build\kernel32-sys-d715e52d58016295268-target\debug\build\kernel32-sys-d715e52d58016295\build-script-build.exe269-target\debug\build\kernel32-sys-d715e52d58016295\build_script_build-d715e52d58016295.exe270-target\debug\build\kernel32-sys-d715e52d58016295\build_script_build-d715e52d58016295.pdb271-target\debug\deps272-(some content omitted...)273-target\debug\examples274-target\debug\fd.exe275-target\debug\incremental276-target\debug\native277-tests278-tests\testenv279-tests\testenv\mod.rs280-tests\tests.rs281-```213+### Regular expression search214 283-If `fd` is called with a single argument (the search pattern), it will perform a recursive search284-through the current directory. To search for all files that include the string "access" in the285-/var/log directory, we can simply run:215+The search pattern is treated as a regular expression. Here, we search for entries that start216+with `x` and end with `rc`:217+``` bash218+> cd /etc219+> fd '^x.*rc$'220+X11/xinit/xinitrc221+X11/xinit/xserverrc222 ```287-> cd /var/log288-> fd access289-cups/access_log290-cups/access_log.1291-cups/access_log.2292-some_program/user_access293-```223 295-The search pattern is treated as a regular expression. To show only entries that start with "access",296-we can simply run:297-```298-> fd '^access'299-cups/access_log300-cups/access_log.1301-cups/access_log.2302-```224+### Specifying the root directory225 304-Note that `fd` does not show hidden files (like `.access_control`) by default. To change this, we can use305-the `-H` (or `--hidden`) option:226+If we want so search a specific directory, it can be given as a second argument to *fd*:227+``` bash228+> fd passwd /etc229+/etc/default/passwd230+/etc/pam.d/passwd231+/etc/passwd232 ```307-> fd -H access308-cups/access_log309-cups/access_log.1310-cups/access_log.2311-some_program/user_access312-.access_control313-```233 315-If we are interested in showing the results from a particular directory, we can specify the root of316-the search as a second argument:234+### Running *fd* without any arguments235+236+*fd* can be called with no arguments. This is very useful to get a quick overview of all entries237+in the current directory, recursively (similar to `ls -R`):238+``` bash239+> cd fd/tests240+> fd241+testenv242+testenv/mod.rs243+tests.rs244 ```318-> cd /etc319-> fd firewall iptables320-simple_firewall.rules321-// TODO: review this with router content322-```245 324-If we work in a directory that is a Git repository (or includes several Git repositories), `fd`325-does not search folders (and does not show files) that match the `.gitignore` pattern. For example,326-imagine we had a `.gitignore` file with the following content:246+### Searching for a particular file extension247+248+Often, we are interested in all files of a particular type. This can be done with the `-e` (or249+`--extension`) option. Here, we search for all Markdown files in the fd repository:250+``` bash251+> cd fd252+> fd -e md253+CONTRIBUTING.md254+README.md255 ```328-*.sh329-```330-In this case, `fd` would not show any files that end in `.sh`. To disable this behavior, we can331-use the `-I` (or `--ignore`) option:332-```333-> fd -I me334-sub_dir/more_dir/even_further_down/not_me.sh335-```256 337-To really search *all* files and directories, we can combine the hidden and ignore features to show338-everything (`-HI`):257+The `-e` option can be used in combination with a search pattern:258+``` bash259+> fd -e rs mod260+src/fshelper/mod.rs261+src/lscolors/mod.rs262+tests/testenv/mod.rs263 ```340-fd -HI 'not|here'341-not_file342-sub_dir/.here_be_tests343-sub_dir/more_dir/.not_here344-sub_dir/more_dir/even_further_down/not_me.sh345-sub_dir/more_dir/not_file346-```264 348-Searching for a file extension is easy too, using the `-e` (or `--file-extensions`) switch for file349-extensions:265+### Hidden and ignored files266+By default, *fd* does not search hidden directories and does not show hidden files in the267+search results. To disable this behavior, we can use the `-H` (or `--hidden`) option:268+``` bash269+> fd pre-commit270+> fd -H pre-commit271+.git/hooks/pre-commit.sample272 ```351-> fd -e sh352-sub_dir/more_dir/even_further_down/not_me.sh353-```273 355-Next, we can even use a pattern in combination with `-e` to search for a regex pattern over the356-files that end in the specified extension.274+If we work in a directory that is a Git repository (or includes Git repositories), *fd* does not275+search folders (and does not show files) that match one of the `.gitignore` patterns. To disable276+this behavior, we can use the `-I` (or `--ignore`) option:277+``` bash278+> fd num_cpu279+> fd -I num_cpu280+target/debug/deps/libnum_cpus-f5ce7ef99006aa05.rlib281 ```358-> fd -e txt test359-fd_examples/desub_dir/old_test.txt360-fd_examples/sub_dir/new_test.txt361-```282 363-What if we wanted to run a command for each of the search results? We can use `xargs` to do that:364-`fd -0 'test' | xargs -0 -I {} cp {} {}.new`283+To really search *all* files and directories, simply combine the hidden and ignore features to show284+everything (`-HI`).285 366-In this example there are a couple things to take note:367- - First we are telling `fd` we want a null character to seperate the files `-0`, this is368- important when passing to `xargs`.369- - Second, we are piping the output to `xargs` and telling this program to expect input null370- terminated with `-0` (the same syntax that `fd` was built with).371- - Then for fun we are using `-I` to replace a string `{}` and lauching `cp` to copy the file `{}`372- to a file ending in `{}.new`.286+### Using fd with `xargs` or `parallel`287 374-`fd` can also show us the absolute path vs. the full path with `-a` (`--absolute-path`):288+If we want to run a command on all search results, we can pipe the output to `xargs`:289+``` bash290+> fd -0 -e rs | xargs -0 wc -l291 ```376-> fd -a new377-/Users/fd_user/fd_examples/sub_dir/more_dir/even_further_down/test_seven.new378-/Users/fd_user/fd_examples/sub_dir/more_dir/even_further_down/testing_eight.new379-/Users/fd_user/fd_examples/sub_dir/more_dir/test_file_six.new380-/Users/fd_user/fd_examples/sub_dir/test_file_five.new381-/Users/fd_user/fd_examples/sub_dir/test_file_four.new382-/Users/fd_user/fd_examples/sub_dir/test_file_three.new383-/Users/fd_user/fd_examples/test_file_one.new384-/Users/fd_user/fd_examples/test_file_two.new385-/Users/fd_user/fd_examples/test_one.new386-/Users/fd_user/fd_examples/this_is_a_test.new387-```292+Here, the `-0` option tells *fd* to separate search results by the NULL character (instead of .293+newlines) In the same way, the `-0` option of `xargs` tells it to read the input in this way .