Operating System - HP-UX
1832413 Members
3087 Online
110041 Solutions
New Discussion

Re: Nullifying the contents of directory

 
Trng
Super Advisor

Nullifying the contents of directory

Hi,

i hv a diretcory called log under /var/adm .log contains multiple log files.is there any command to nullifying the contents of entire directory,rather than nullifying one by one file under log.my requirement is to nullify all files under log directory.


rgds
administrator
4 REPLIES 4
Patrick Wallek
Honored Contributor

Re: Nullifying the contents of directory

The easiest thing I can think of is:

cd /var/adm/log
for FILE in $(ls -1)
do
> ${FILE}
done

Before you run that you should do:

for FILE in $(ls -1)
do
echo ${FILE}
done

To make sure you are doing only the files you want.

Something like:

> *

****MIGHT**** work, but it could be risky.
john D_3
Frequent Advisor

Re: Nullifying the contents of directory

for i in `ls /var/adm/*.log
do
> $i #[ It is > sign]
done

Bill Hassell
Honored Contributor

Re: Nullifying the contents of directory

It is easy to nullify the files but not a good idea until you have examined the logs. Many of them will contain error messages, some of which may be critical for your system. These logs are the only way to check the health of your system.

What is more useful is to scan the logs with something like grep looking for errors, warnings and failures, then copy the logs to another location and compress them to save space. Then you can nullify the logs.


Bill Hassell, sysadmin
Trng
Super Advisor

Re: Nullifying the contents of directory

Thanks for the replies.
administrator