Linux / Unix: Find And Remove Files With One Command On Fly

Linux / Unix: Find And Remove Files With One Command On Fly

To find and remove files with a single command on Linux or Unix, you can use the find command with the -delete option.

Here's an example of how you can use find to delete all files in the current directory that have the .tmp extension:

ref‮‬er to:lautturi.com
find . -name "*.tmp" -delete

This command will search for all files in the current directory (.) and its subdirectories that have the .tmp extension, and delete them.

You can also use the find command to delete files based on other criteria, such as their size, modification time, or owner. For example, to delete all files that are larger than 100MB, you can use the -size option:

find . -size +100M -delete

Keep in mind that the find command operates recursively, so it will delete files in subdirectories as well. Use caution when using the -delete option, as it is not reversible and deleted files cannot be recovered.

For more information about the find command and its available options, you can consult the find man page or use the find --help command.

Created Time:2017-10-29 22:08:59  Author:lautturi