Shell Script to Periodically Delete Only 0 Bytes of Files

Asked 1 years ago, Updated 1 years ago, 135 views

The following folder configurations are available:

/var/tmp/Organization Code/log

There are many 0 bytes files under this log directory and I would like to delete them all periodically.
The directory also contains other files and folders that should never be deleted.

I thought about the following commands, but do you have any concerns?

find/var/tmp/*/log-size 0c-execrm{}\;

I've looked into various things, but I'm not sure if Unix is appropriate because I'm a beginner.
The environment is Solaris 11, bash.
I think it's certain to write commands for a few minutes with the organization code fixed, but I don't think it's good because every time the organization code increases or changes, the shell also needs maintenance.

If you are familiar with it, could you please give me some advice?
Thank you for your cooperation.

unix solaris

2022-09-30 19:47

1 Answers

First, Solaris and Linux are completely different operating systems.You should know exactly what your operating system is.

As for the next find, in addition to the ones that come with the OS, there may be other items that have been installed after GNU find.You should know which find you want to use and refer to the appropriate documentation.Using the OS supplied with /usr/bin/find and path to eliminate inadvertent dependencies is another way.

/usr/bin/find/var/tmp/*/log-size 0c-execrm{}\;

There is almost no problem withTo see what the outcome will be,

/usr/bin/find/var/tmp/*/log-size 0c-execchorm{}\;

Adding echo as shown in to verify operation is another way.

Renya Gaikoku suggested -empty or -delete in her comments, but as far as Solaris find document does not mention such features, it may not work as intended.+ can be used.GNU find will have both features.


2022-09-30 19:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.