1827713 Members
2633 Online
109967 Solutions
New Discussion

Re: Looking for commands

 
SOLVED
Go to solution
khilari
Regular Advisor

Looking for commands

Hey people, i was looking for some commands.

1). How would u trim log files.
2). How do u find files which are most new?
3). How do u find files which are using the most space?

thanks alot.
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor
Solution

Re: Looking for commands

Hi:

1. The best way to empty a log file is simply:

# cat /dev/null > logfile

2. To find files that are newer (more recently modified than some time):

# find /yourpath -xdev -type f -mtime +30

...this finds files in /yourpath that havn't been modified in the last 30-days

# touch -amt 02110000 /tmp/myref
# find /yourpath -xdev -type f -newer /tmp/myref

...this form finds files that are newer than the reference file /tmp/myref

3. To find files greater than a particular size:

# find /yourpatch -xdev -type f -size +100000c

...returns files whose size exceeds 100,000 characters.

# du -xak /yourpath | sort -k1nr

...return all files and directories in /yourpath and list them in descending block (1K size) order.

The manpages for 'find' and for 'du' should be read with these examples in mind.

Regards!

...JRF...
Arunvijai_4
Honored Contributor

Re: Looking for commands

Hi Khilari,

Q1). How would u trim log files.

Ans : # >/var/adm/syslog/syslog.log will trim syslog.log file

Q2). How do u find files which are most new?

Ans : # find . -type f -ctime -1 -exec ll {} \;

Q3). How do u find files which are using the most space?

# ls -lR | sort +4 -5nr | more

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Steven E. Protter
Exalted Contributor

Re: Looking for commands

Shalom Khilari,

I have several ways I handle this.

On some servers, I manually trim using sam.

On most servers, I weekly back up the log files and do this command on the ones I wish cut down:

> logfilename

This second method is totally done via cron.

/var/adm/btmp and /var/adm/wtmp take up a lot of space, as do mail.log and syslog.log. The first two are critical for security. If you don't keep them, you will have problems on a Security audit.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Volker Borowski
Honored Contributor

Re: Looking for commands

Hi,

more comfortable tools are "logrotate" and "logadm".

Don't know if they are available as binaries for HPUX, you might need to get Linux source and compile on your own.

Esp. logadm has a ton of options to do nice things in logfile administration. I.e. restart the process which is writing the file.

Zeroing out a logfile as described above is easy and comfortable, but if you have a monitoring process on that logfile (i.e "tail -f") you may loose messages, because you will have to restart this monitoring process in addition. "logadm" is a very comfortable way to do this.

Volker

Indrajit_1
Valued Contributor

Re: Looking for commands

Hi;

Try this..

1 #cat /dev/null /(e.g. /dev/adm/wtmp)

2 #find / -type f -mtime +24 -print

3 #find / -type f -size +100000c

3 #du -sk / |sort -rn

Cheers
indrajit
Never Ever Give Up
Muthukumar_5
Honored Contributor

Re: Looking for commands

1). How would u trim log files.

Simply as,

> Logfile

will do it. Else use sam to trim logs.

2). How do u find files which are most new?

# find / -xdev -type f -mtime -1

which will give today's update file. Change with + to get more files within that time period.

3). How do u find files which are using the most space?

# du -ks | sort -rnk 1 | more

will give it.

--
Muthu
Easy to suggest when don't know about the problem!
Richard Darling
Trusted Contributor

Re: Looking for commands

I use sam to trim the files, as mentioned in an earlier post.
Routine Tasks-> System Log Files-> select files to trim.
The one thing that you need to keep in mind is that if the file is on use that you are trying to trim a backup is created with an extension SAMTRM of at the end of the file name. You'll need to delete this file if you are looking to gain space.

I don;t know how familar you are with the different "trim" commands mentioned above, but most will create a new file with no records. Make sure that is what you want.

Richard
Geoff Wild
Honored Contributor

Re: Looking for commands

You can get logrotate here:

http://hpux.ee.ualberta.ca/hppd/hpux/Sysadmin/logrotate-2.5/

Others have answered your questions - so I won't repeat them.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.