LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > mosiac
User Name
Password

Notices


Rate this Entry

Feet in the Fire

Posted 07-15-2013 at 02:16 PM by mosiac

I didn't even realize that this site had a blog so I thought I'd get started and post something. I'm a Linux / Windows / VMware admin who got thrown into the mix instead of gently let down into it (something I'm sure many people are familiar with).

Anyway today's major issue was trying to figure out how to calculate space used by log files generated by a database over a specific date.

Well I knew that "df -h" would give me all the space used on a drive and "du -h /directory" would give me how much space that specific directory is but how do I add in the date of the files I need.

I had to come to this forum and ask for help because all I really had going on was

Code:
find /directory -type f -name "*.log*" -cmin -610 2> /dev/null | xargs du -b -h 2>/dev/null | awk '{total += $1; print $0} END{print total}'
Which if we break it down does a find for file types in a directory with the name *log and then a creation time of 610 minutes ago, which at the time I wrote it was midnight, it pumps that out to my term which I think run du on and pump that out to an awk statement to give me the total space used.

This was fine but I really didn't like the ctime part it wasn't specific enough and would need to be changed to recalculate for what time I was running it so I posted the question and I got this from user druuna (THANKS AGAIN!)

Code:
touch --date="2013-07-15 00:00:00" /tmp/token1
touch --date="2013-07-15 23:59:59" /tmp/token2
find /dirX -type f -newer /tmp/token1 -not -newer /tmp/token2 -exec stat -c%s {} \; | awk '{total += $1;print}END{print total}'
That gave me my timeframe to the specifics I was looking for and it worked out great. The next step will be pruning 30 gigs of log files generated in less than 24 hours...
Posted in Uncategorized
Views 892 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 10:36 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration