Skip to content
Myr

Add a section about "removing files"

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

see #387

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

  • other:+22 added−0 removed

1 file+22 added−0 removed

modified:README.md+22 added
445 unmodified lines
446```447Here, the `-0` option tells *fd* to separate search results by the NULL character (instead of448newlines). In the same way, the `-0` option of `xargs` tells it to read the input in this way.449450### Deleting files451452You can use `fd` to remove all files and directories that are matched by your search pattern.453If you only want to remove files, you can use the `--exec-batch`/`-X` option to call `rm`. For454example, to recursively remove all `.DS_Store` files, run:455``` bash456> fd -H '^\.DS_Store$' -tf -X rm457```458If you are unsure, always call `fd` without `-X rm` first. Alternatively, use `rm`s "interactive"459option:460``` bash461> fd -H '^\.DS_Store$' -tf -X rm -i462```463464If you also want to remove a certain class of directories, you can use the same technique. You will465have to use `rm`s `--recursive`/`-r` flag to remove directories.466467Note: there are scenarios where using `fd … -X rm -r` can cause race conditions: if you have a468path like `…/foo/bar/foo/…` and want to remove all directories named `foo`, you can end up in a469situation where the outer `foo` directory is removed first, leading to (harmless) *"'foo/bar/foo':470No such file or directory"* errors in the `rm` call.471472### Troubleshooting473474#### `fd` does not find my file!475
60 unmodified lines