Solved

RHEL, How to determine largest files

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

808 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