[LINUX] -Delete is good for deleting files searched by find

Introduction

I had the task of writing a shell script to find and delete the backed up files from the database. I knew that there was a find command to search for files, but I was looking for a command to search → delete all at once, so I will summarize it.

There seems to be an action called -exec

Many sites have come up with the idea that you should execute the -exec action while googled the command that I was looking for to do everything from search to delete.

Something like this.

sample


# find /directory/~ -exec ls -l {} \;

Almost all sites used this style of writing, but I wasn't sure.

There seems to be a simple command called -delete

I asked a senior at the company. It seems that you should add the -delete option at the end.

sample


# find /directory/~ -delete;

This is easier, isn't it?

that's all.

Recommended Posts

-Delete is good for deleting files searched by find
Bakthat is good for backup, isn't it?
Is there a good sample code for nosetests?