nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Find Files By Size and Print Results

This is a discussion on Find Files By Size and Print Results within the Getting started tutorials forums, part of the Linux Getting Started category; Hello Friends, This is a basic find command that I modified a bit to show the size of the file ...


Go Back   nixCraft Linux Forum > Linux Getting Started > Getting started tutorials

Linux answers from nixCraft.


Getting started tutorials So much to read, so little time! If that is your problem, we have solution. Read our FAQ and tutorials to help you cut through the clutter of information overload. Only members of "contributors" group can post new tutorials. Other members can just reply to thread.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 14-11-2009, 09:50 PM
jaysunn's Avatar
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Scripting language: BASH - Learning Ruby
Posts: 602
Thanks: 61
Thanked 80 Times in 72 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default Find Files By Size and Print Results

Hello Friends,

This is a basic find command that I modified a bit to show the size of the file it finds.

This is extremely helpful when trying to locate files that are taking up large quantities of space. e.g. apache log files, mysql logfiles.


This will show files in / that are larger than 20MB in / partition.
Code:
[root@badassweb1 ~]# find /root -type f -size +20000k -exec ls -lh {} \; | awk '{print $9 ": " $5}'
/root/mysqldb.sql: 125M
/root/blit.sql: 58M
You can also change the command to look in other places, change the value in red to any partition on your server. Lets say apache logs for this one.

Code:
[root@badassweb1 ~]# find /usr/local/apache/logs  -type f -size +20000k -exec ls -lh {} \; | awk '{print $9 ": " $5}'
/usr/local/apache/logs/wvmagic/access_log: 58M
/usr/local/apache/logs/933therazor/access_log: 53M
/usr/local/apache/logs/wrnn/access_log: 43M
/usr/local/apache/logs/tampabaysq105/access_log: 30M
/usr/local/apache/logs/thewendywilliamsexperience/access_log: 72M
Notice that the awk piece prints that size as well. This is what was helpful to me.

Hope this helps,

Jaysunn
__________________
Have a look at what I have been working on
http://www.shellasaurus.com
Reply With Quote
The Following User Says Thank You to jaysunn For This Useful Post:
raj (20-11-2009)
  #2 (permalink)  
Old 20-11-2009, 12:39 AM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 307
Thanks: 42
Thanked 8 Times in 8 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default

Code:
find /usr/local/apache/logs  -type f -size +20000k -exec ls -lh {} \; | awk '{print $9 ": " $5}'
I run and I see very large files (my path is /corpwww/logs). Each file is 5 or 6gb. can I remove them?

By the way your location is set to 41.332032,-73.089775?? Is it google map location or just some random stuff fro /dev/random ?
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #3 (permalink)  
Old 20-11-2009, 12:56 AM
jaysunn's Avatar
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Scripting language: BASH - Learning Ruby
Posts: 602
Thanks: 61
Thanked 80 Times in 72 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default

What's Up Raj,
That location is for real. Derby CT, United States.

As for the logs.

Apache access_logs are used to show the access hits from the external users IP as well as other information. If you are not using those logs for gathering stat data then feel free to remove them. Perform a graceful restart of apache and it will recreate them at 0.

As for the apache error_logs, if you are not using those to gather data. They also can be removed. They will also get recreated when running a apache graceful restart.

Code:
$/usr/local/apache/bin/apachectl graceful
Also have a look at logrotate. This will help you keep your apache log files in check.

On redhat, the file is

Code:
/etc/logrotate.conf
Jaysunn
__________________
Have a look at what I have been working on
http://www.shellasaurus.com
Reply With Quote
Reply

Tags
find , find file linux , find file unix , linux find a file by size


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Awk Find Smallest And Largest File Size in Directory Phass Shell scripting 4 26-07-2009 05:40 PM
Shell Script To Check Null Files ( size greater than zero ) shellscript916 Shell scripting 1 22-05-2009 12:37 AM
How to find Total nuber files/size in a server? mahi Solaris/OpenSolaris 1 02-10-2008 11:48 AM
Load balancing pooling print jobs using CUPS print queues raj Getting started tutorials 0 16-01-2007 09:08 PM
moving files based on size kavi Shell scripting 2 11-11-2005 05:17 PM


All times are GMT +5.5. The time now is 05:32 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38