1

I am am trying to run the below command to delete tmp folders greater than 3 minutes using the below:

 find /tmp/tmp* -mmin +3 -exec rm -rf {} \;

The above command fails. Why?

find /tmp/tmp* -mmin +3 -exec rm -rf {} \;
find: `/tmp/tmpAJaHLX/crashes': No such file or directory
find: `/tmp/tmpbM5ac8/minidumps': No such file or directory
find: `/tmp/tmpbM5ac8/crashes/events': No such file or directory
find: `/tmp/tmpdQACdf/gmp': No such file or directory
find: `/tmp/tmpo1tbqu/thumbnails': No such file or directory
find: `/tmp/tmpW91Yel/extensions': No such file or directory
3
  • 1
    Why are you deleting random stuff from /tmp? Are you aware that /tmp holds running programs' temporary files? But anyway that's likely because you don't have permissions on those files / folders.
    – kos
    Mar 16, 2016 at 14:00
  • I am root and the proccess that creates those folders do not do cleanup. Yes..I know what the tmp dir does and its used.
    – Tampa
    Mar 16, 2016 at 14:12
  • 1
    find could lists folder and file and it could be due to rm execution order
    – Lety
    Mar 16, 2016 at 14:25

1 Answer 1

2

What you're seeing is likely a result of the find command's traversal order.

e.g. given a simple directory

$ find somedir
somedir
somedir/file

then

$ find somedir -exec rm -rfv {} \;
removed ‘somedir/file’
removed directory: ‘somedir’
find: `somedir': No such file or directory

You can force a depth-first traversal using the -depth option, i.e.

$ find somedir -depth -exec rm -rfv {} \;
removed ‘somedir/file’
removed directory: ‘somedir’

does not result in error.

Alternatively, you can use the simpler find somedir -delete which (as noted in the manual page) turns on the -depth option

-delete
       Delete files; true if removal succeeded.  If the removal failed,
       an  error message is issued.  If -delete fails, find's exit sta‐
       tus will be nonzero (when it eventually exits).  Use of  -delete
       automatically turns on the -depth option.
1
  • 1
    You can also suggest to setup a cron job, if the command needs to be executed every X minutes.
    – kukulo
    Mar 16, 2016 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .