Skip to content
Myr

Small update for the tutorial

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 0cd9d8c · Browse files · 1 file+5 added−25 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+5 added−25 removed

  • other:+5 added−25 removed

1 file+5 added−25 removed

modified:README.md+5 added-25 removed
213 unmodified lines
214this_is_a_test215```216217The search pattern is treated as a regular expression. To show only entries that start with "test",218we can simply run:218we can call:219```220> fd '^test'221sub_dir/more_dir/even_further_down/test_seven222sub_dir/more_dir/even_further_down/testing_eight
79 unmodified lines
302sub_dir/more_dir/even_further_down/not_me.sh303sub_dir/more_dir/not_file304```305306Searching for a file extension is easy too, using the `-e` (or `--file-extensions`) switch for file306Searching for a file extension is easy too, using the `-e` (or `--extension`) switch for file307extensions:308```309> fd -e sh310sub_dir/more_dir/even_further_down/not_me.sh
6 unmodified lines
317fd_examples/desub_dir/old_test.txt318fd_examples/sub_dir/new_test.txt319```320321What if we wanted to run a command for each of the search results? We can use `xargs` to do that:322`fd -0 'test' | xargs -0 -I {} cp {} {}.new`323324In this example there are a couple things to take note:325 - First we are telling `fd` we want a null character to seperate the files `-0`, this is326 important when passing to `xargs`.327 - Second, we are piping the output to `xargs` and telling this program to expect input null328 terminated with `-0` (the same syntax that `fd` was built with).329 - Then for fun we are using `-I` to replace a string `{}` and lauching `cp` to copy the file `{}`330 to a file ending in `{}.new`.331332`fd` can also show us the absolute path vs. the full path with `-a` (`--absolute-path`):321If we want to run a command for each of the search results, we can use the `-0` option to pipe322the output to `xargs`:323```334> fd -a new335/Users/fd_user/fd_examples/sub_dir/more_dir/even_further_down/test_seven.new336/Users/fd_user/fd_examples/sub_dir/more_dir/even_further_down/testing_eight.new337/Users/fd_user/fd_examples/sub_dir/more_dir/test_file_six.new338/Users/fd_user/fd_examples/sub_dir/test_file_five.new339/Users/fd_user/fd_examples/sub_dir/test_file_four.new340/Users/fd_user/fd_examples/sub_dir/test_file_three.new341/Users/fd_user/fd_examples/test_file_one.new342/Users/fd_user/fd_examples/test_file_two.new343/Users/fd_user/fd_examples/test_one.new344/Users/fd_user/fd_examples/this_is_a_test.new324> fd -0 'test' | xargs -0 wc -l325```