How to find and delete files by their name recursively in GNU/Linux
To find and delete files in GNU/Linux we usually use the find command.
In the following example we will search and delete in the current directory (.
) and recursively in all subdirectories all files (-type f
) that contain in their name (-name
) the text “sync-conflict” ('*sync-conflict*'
):
$ find . -type f -name '*sync-conflict*' - exec rm "{}" +
"{}"
will be replaced by the output of find+
will consider all files returned by find,;
will only consider one (first or last returned by find?)
You can limit the depth of find recursion with -maxdepth
(find -maxdepth 2, for example).