Forrest logo
back to the find tool

xargs:tldr:67693

xargs: Delete all files with a `.backup` extension (`-print0` uses a null character to split file names, and `-0` uses it as delimiter).
$ find . -name ${'*-backup'} -print0 | xargs -0 rm -v
try on your machine

This command is used to find and delete files matching a certain pattern or name.

Here's a breakdown of each part of the command:

  1. find . -name ${'*-backup'}: This part starts the find command. The period (.) represents the current directory, and -name is used to specify the name pattern to search for. ${'*-backup'} is a shell variable that is expanded to *-backup, indicating that we're searching for files ending with "-backup" in their name.

  2. -print0: This option is used to print the found filenames, separated by null characters. It's useful when dealing with filenames containing spaces or special characters.

  3. |: This is a pipe symbol, which redirects the output of the previous command (find) to the input of the next command (xargs).

  4. xargs -0 rm -v: xargs is a command that reads items from standard input (in this case, the filenames from find) and executes another command (rm) with those items as arguments. -0 tells xargs to expect null-delimited input. rm is the command used to remove files, and -v is an option to make it verbose, which means it will display the names of the files being deleted.

So, overall, this command finds all files in the current directory and its subdirectories that match the pattern *-backup in their name, prints their names (using null characters as separators), and then uses xargs to delete the found files with rm while also displaying their names.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the find tool