# How to delete a large number of files in a directory - Linux

Source: https://www.hukot.net/community/en/tutorials/how-to-delete-a-large-number-of-files-in-a-directory-linux
Updated: 2026-11-25

It may be necessary to clean up a directory from unnecessary data. This often involves "**cache**" directories. In a Linux shell, you can use various combinations of commands, but a very effective method for cleaning up thousands of files is to use the **rsync trick**:

```bash
mkdir new_directory
rsync -a --delete new_directory/ cache/
```

> [!WARNING]
> Keep the order: the empty directory comes first, the directory to be emptied last. If the arguments are swapped, or `new_directory` is not empty, rsync deletes or overwrites other data.

From the example, you create a "**new\_directory,**" which is, of course, empty, and the directory containing the files to be deleted is "**cache.**"
