Operating System - HP-UX
1821984 Members
3396 Online
109638 Solutions
New Discussion юеВ

How do I delete ...*.log + clear many logs out ??

 
SOLVED
Go to solution
someone_4
Honored Contributor

How do I delete ...*.log + clear many logs out ??

Ok we have an app that makes several logs.
And I was trying to clear them out by doing
> *.log and this didnt clear out all the logs.
It make a file called *.log but I am scared to delete this file cuss when I do a simple
cp *.log it copies all the files. So I am thinking when I do an rm *.log it will delete all the log files. So how do I delete just the
*.log. Plus how do I clear out many logs at the same time with one command?

Thanks

Richard
5 REPLIES 5
John Poff
Honored Contributor
Solution

Re: How do I delete ...*.log + clear many logs out ??

Richard,

I just tried this on a test box here so it should work for you. Try

mv '*.log' junk.log

That should rename just the *.log file for you.
James R. Ferguson
Acclaimed Contributor

Re: How do I delete ...*.log + clear many logs out ??

Hi Richard:

To remove just the file named "*.log" do this:

# rm -i \*.log

Note the interactive remove (-i). This gives you the chance to confirm what you're going to do. The backslash (\) in front of the star (*) prevents the shell from treating the asterisk as a wildcard character.

To remove all files ending in ".log" you could do this:

# cd
# find . -name "*.log" -exec rm -i {} \;

Regards!

...JRF...
Rodney Hills
Honored Contributor

Re: How do I delete ...*.log + clear many logs out ??

To delete the file, enter -- rm \*.log

To erase multiple files, enter --
ls *.log | xargs -n1 cp /dev/null

This will copy /dev/null to each file that ends with .log
There be dragons...
John Poff
Honored Contributor

Re: How do I delete ...*.log + clear many logs out ??

As for a way to null out the log files, you could try a script like this:

#!/bin/sh

for f in *.log
do
>$f
done


Satish Y
Trusted Contributor

Re: How do I delete ...*.log + clear many logs out ??

Hi Richard,

John's solution is safer because if there are any active log files they will be removed with rm command but u can't recover the space.

for deleting *.log file use:

# rm "\*.log"

Cheers...
Satish.
Difference between good and the best is only a little effort