Tag Info

Hot answers tagged


POSIXly: find /test/. ! -name . -type d -mtime +0 -exec rm -rf {} \; -prune (we use -prune for the directories that we successfully remove so that find doesn't complain that they're suddenly gone). In any case, note that the modification time (as checked by -mtime above) of a directory file only reflects the last time an entry was added, removed or ...


-exec indeed can be used as a predicate. find(1): Execute command; true if 0 status is returned. So this example would be: find . -type f -exec sh -c 'file "$0" | grep -q Matroska' '{}' ';' -and -delete Obviously, instead of -delete there can be -ls or -print0 or more predicates.


Well, the -mmin primary is a GNUism that is most likely not supported on AIX as it is a silly expansion compared to what the BSD people and I used as extension in the 1980s already. Given the fact that sfind compiles fine on AIX, I recommend: sfind . -mindepth 1 -type d -mtime +24h -exec rm -rf {} + The code is in schilytools at: ...


As @meuh said in his comment, you could use /test/* instead of /test. Your command could then look similar to this: find /test/* -type d -mmin +1440 | xargs rm -rf In this case only the subfolders of /test would be removed.

Only top voted, non community-wiki answers of a minimum length are eligible