PDA

View Full Version : Need help sending results of find into rmdir



dwoeltje
30-Apr-2012, 18:14
Basically, I'm attempting to do the following but it errors out so it must not be possible this way. However, there must be some alternate way of accomplishing it. I just need a little assistance.

This is what I tried to do:

find /var/log/audit -mtime 5 | rmdir --ignore-fail-on-non-empty

I'm trying to get rmdir to use the output of the find command as input for removing directories that are not empty and are more than 5*24 (in other words, 5 days) old.

malcolmlewis
30-Apr-2012, 18:39
Basically, I'm attempting to do the following but it errors out so it
must not be possible this way. However, there must be some alternate way
of accomplishing it. I just need a little assistance.

This is what I tried to do:

find /var/log/audit -mtime 5 | rmdir --ignore-fail-on-non-empty

I'm trying to get rmdir to use the output of the find command as input
for removing directories that are not empty and are more than 5*24 (in
other words, 5 days) old.




Hi
Use exec and rm ;


find /var/log/audit -mtime 5 -exec rm -r {} \;


--
Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.1 (x86_64) Kernel 3.1.10-1.9-desktop
up 1 day 12:49, 3 users, load average: 0.00, 0.01, 0.05
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

jmozdzen
01-May-2012, 14:33
Basically, I'm attempting to do the following but it errors out so it must not be possible this way. However, there must be some alternate way of accomplishing it. I just need a little assistance.

This is what I tried to do:

find /var/log/audit -mtime 5 | rmdir --ignore-fail-on-non-empty

I'm trying to get rmdir to use the output of the find command as input for removing directories that are not empty and are more than 5*24 (in other words, 5 days) old.

In addition to Malcom's answer - the original command did not work for multiple reasons:

The used syntax makes the output of the first command the "standard input" of the second command, not its parameters... you might have accomplished that via "rmdir --ignore-fail-on-non-empty $(find /var/log/audit -mtime 5)" in a bash script (other shells may use a different syntax).

But still, "rmdir" will only remove empty directories. "--ignore-fail-on-non-empty" will simply not report non-empty directories as errors, so that you can invoke it with i.e. wildcards and still check it's rc for "more severe causes of failure". So, non-empty directories are preserved.

Regards,
Jens