Solved

RHEL, How to determine largest files

Posted on 2012-04-05
3
323 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 77

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

932 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

14 Experts available now in Live!

Get 1:1 Help Now