Solved

RHEL, How to determine largest files

Posted on 2012-04-05
3
320 Views
Last Modified: 2012-04-06
I used the following command to find out which directories were taking up space on my machine which is out of disk space

du -xsk /* | sort -nr

42088124        /var

Open in new window


How can I determine which are the largest files withing /var
0
Comment
Question by:Los Angeles1
3 Comments
 
LVL 76

Assisted Solution

by:arnold
arnold earned 166 total points
ID: 37813113
You can do find /var -size +200000c -ls| awk ' { print $7,$NF } ' | sort -rn | more

The size as used here refers to 200000c 200000bytes. You can adjust it lower or higher
Awk will split the ls -l which is what -ls is in the find command on spaces the seventh item is the size of the file, and NF represents the total number of columns in each line adding the $NF represents the last value in each line.

You may have a large file that has no reference within the filesystem I.e. a log that is being used by a running process, but the filename has been deleted. As long as a process has a filehandle, the file remains in existance.  For this you would use lsof and other tools to locate all open files by running processes to locate one.
Example would be an apache process that was writing access.log and then some one did rm access.log
While the file is no longer referenced within the log filesystem, the data is still being written to it as long as a hup, reload are not sent to the apache process at which point it will disconnect and reattach to a new log file and the amount of space previously used by the deleted access.log file will be freed.
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 167 total points
ID: 37813148
Why not

du -xsk /var/* | sort -n

The largest file will appear at the bottom of the list.

Or with subdirectories:

 find /var -type f -printf "%k %p\n" |sort -n

Again, the largest file will appear at the bottom of the list.

wmp
0
 
LVL 30

Accepted Solution

by:
Kerem ERSOY earned 167 total points
ID: 37814752
Hi,

I guess this command will do for you:

# find . -type f -exec du -k {} \; | sort -r -n 

Open in new window


The first part finds files and then executes du. Then the second part sorts it. if you can apply " | head -10" and it will give you 10 largest files.

Feel free to change the "." after find to any valid path to examine other paths.

Cheers,
K.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now