delete all files within a directory that are older than 1 day

11,878

The {} stands for the name of the file(s) found.

The + sign (instead of a ;) means that this command accepts multiple file names in the same command, so that find can run much faster because it is run less times. The number of files added to each execution of the command is limited by the maximum length of the command line find is willing to use.

Share:
11,878
stdcerr
Author by

stdcerr

Coding mostly on embedded systems (24/7/365 uptime) to make a living at daytime, coding on a variety of systems (x86, arm) for fun at nighttime, preferences: Linux, C & C++. Always interested in learning other ways/better ways to solve problems!

Updated on June 27, 2022

Comments

  • stdcerr
    stdcerr almost 2 years

    I need to ensure that I have no old files left in my directory so what I think I do is

    find . -type f -mtime +1 -delete
    
    • i got that from the find man page but then

      find . -type f -mtime +1 -exec /bin/rm

    but again, now told that find: -exec requires an argument - didn't iI pass this. So I started Googling and I found that my command needs to look likee this:

    find . -type f -mtime +1 -exec /bin/rm -f {} +
    

    and now I'm just wondering what the two {} s and the + sign are for. Can anyone help me here?

    Thanks!