linux - How do I delete all files/driectories within my directory that are older than a day? -


this question has answer here:

i’m using amazon linux bash shell. wanted delete directories , files more day old in directory, tried running statement

sudo find /usr/java/jboss-as-7.1.3.final/standalone/tmp/vfs -name "*" -type f -mmin +1441 -delete 

however, after running above, when check directory, there still child directories older day …

[mike@mymachine /]$ ls -al /usr/java/jboss-as-7.1.3.final/standalone/tmp/vfs total 240 drwxr-xr-x  17 jboss jboss  4096 sep 20 23:24 . drwxr-xr-x   5 jboss jboss  4096 jun 24  2013 .. drwxr-xr-x 186 jboss jboss 24576 sep 20 21:12 deployment2368807199465dba drwxr-xr-x  93 jboss jboss 20480 sep 20 23:23 deployment2617ff35c8bff41a drwxr-xr-x   6 jboss jboss 24576 sep 19 20:26 deployment3571c00385713fe3 drwxr-xr-x   2 jboss jboss 20480 sep 19 17:39 deployment3d351ede58f283dd drwxr-xr-x   2 jboss jboss 20480 sep 19 15:25 deployment4290f5e8ea8315f2 drwxr-xr-x 297 jboss jboss 24576 sep 22 03:30 deployment9b31473d9eac9da0 drwxr-xr-x   2 jboss jboss 24576 sep 20 18:56 deploymentceee45a133e7107d drwxr-xr-x  93 jboss jboss 20480 sep 19 18:55 deploymentefd5fbdbb2c4c444 drwxr-xr-x   2 jboss jboss  4096 sep 20 18:57 temp165d12bb32054951 drwxr-xr-x   2 jboss jboss  4096 sep 19 17:40 temp32dd5d98d5a4b497 drwxr-xr-x   2 jboss jboss  4096 sep 19 15:26 temp59d119fda3e5ddc4 drwxr-xr-x   2 jboss jboss  4096 sep 19 20:27 temp7f6ba3704ffeea57 drwxr-xr-x   2 jboss jboss  4096 sep 20 23:23 temp861658110cf44173 drwxr-xr-x   2 jboss jboss  4096 sep 19 18:56 tempcdad4bb17e60cb75 drwxr-xr-x   2 jboss jboss  4096 sep 20 21:13 tempe1ee5a5f7f5c7636 

what right way write statement delete in directory older day?

edit: hey you’re suggestion didn’t work. got error

[mike@mymachine ~]$ sudo find /usr/java/jboss/standalone/tmp/vfs/ -mindepth 1 -mtime +1 -delete find: cannot delete `/usr/java/jboss/standalone/tmp/vfs/deploymentefd5fbdbb2c4c444': directory not empty find: cannot delete `/usr/java/jboss/standalone/tmp/vfs/deployment3571c00385713fe3': directory not empty 

try using '-exec' option instead of '-delete', can add command want on each file, including scary 'rm -rf'.

for example, call 'echo -n' on every file older day, run following. note '{}' placeholder found file/directory.

sudo find /usr/java/jboss-as-7.1.3.final/standalone/tmp/vfs -mindepth 1 -mmin +1441 -exec echo -n {} \; 

edited include '-mindepth 1', otherwise root search directory included in results.

so, recursively delete older 1 day in specified directory:

sudo find /usr/java/jboss-as-7.1.3.final/standalone/tmp/vfs -mindepth 1 -mmin +1441 -exec rm -rf {} \; 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -