Unix shell script for finding top ten files of maximum size


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unix shell script for finding top ten files of maximum size
# 1  
Old 02-13-2008
Unix shell script for finding top ten files of maximum size

I need to write a Unix shell script which will list top 10 files in a directory tree on basis of size. i.e. first file should be the biggest in the whole directory and all its sub directories.
Please suggest any ideas
# 2  
Old 02-13-2008
Quote:
Originally Posted by abhilashnair
I need to write a Unix shell script
You don't need a "script", it fits into a single line:

find /start/dir -type f -exec du {} \; | sort -rn | head -10

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 02-13-2008
Thanks it is listing , But the size that shows when i run ls -l command and the size that is showing for this command is different can you please let me know the reason

example :

$ ll /pfta02/10.001
-rw-rw-rw- 1 pnt pf 87843360 Feb 6 02:21 /pfta02/10.001

$ find /pfta03 -type f -exec du {} \; |sort -rn | head -1
171572 /pfta02/10.001

why the size listing is as 171572 instead of 87843360 ... IS any convertion happening ?..
# 4  
Old 02-13-2008
ls -l will give the output of the total directory links , so dont trust it, du is the exact form to get the info, above commands are perfectly true
# 5  
Old 02-13-2008
I tried the command but I am getting following output for all files in the entire dir tree

find: /dir/filename: Value too large to be stored in data type
# 6  
Old 02-14-2008
Any thoughts on this?
# 7  
Old 02-14-2008
Quote:
Originally Posted by maheshwin
ls -l will give the output of the total directory links , so dont trust it, du is the exact form to get the info, above commands are perfectly true

-rw-rw-rw- 1 pnt pf 87843360 Feb 6 02:21 /pfta02/10.001

Type of file: - (regular)
Access permission: rw-rw-rw- (readable/writable for everyone)
(Directory) links: 1 (usually 1 for a regular file, unless there are hard links)
owner: prt
group: pf
actual size: 87843360
date of last modification: Feb 6 02:21
filenaam: /pfta02/10.001

So the difference in size has nothing to do with the number of directory links, which is 1 in this case.


The "du" command, without options, reports the size in full disk blocks (usually 512 bytes) allocated by the file, where "ls -l" reports the size of the effective data in the file.

For each file at least 1 full disk block is allocated (actually 2 disk blocks), even of it contains just 1 byte of data.

Files always allocate space in full disk blocks.

Since the "du" commands reports in disk blocks, the result will always be a little bit more than the size reported by "ls -l".

The size of the file = 87843360 bytes
To store this amount of bytes at least 87843360/512 = 171569,0625 disk blocks are needed.

Rounded this would be 171570 full disk blocks. At least 1 extra block is needed, which makes it 171571.

The "du" command reports a size of 171572 blocks which is still 1 block more.

This means the file is most likely split up in 2 fragments.

Where the last block in each segment is not fully filled.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with shell script - not finding files

Hello, I have a shell script like the one below but cannot get it working: #!/bin/bash #$ -cwd CHR=$2 # directories ROOT_DIR=./ RESULTS_DIR=${ROOT_DIR}results/ # executable SHAPEIT_EXEC=${ROOT_DIR}shapeit.v2.r727.linux.x64/shapeit.v2.r727.linux.x64 # parameters THREAT=5... (1 Reply)
Discussion started by: wmelroy
1 Replies

2. Shell Programming and Scripting

Unix shell script to query linux top consuming processes

Hi All, O/S: Linux 86x64 Red Hat I have a sql script that queries top consuming processes of Linux using TOP commnd. Now I need to automate this task and pass the top processes i.e., PID to the sql script through unix shell script. Could anyone please let me know how to achieve this. ... (2 Replies)
Discussion started by: a1_win
2 Replies

3. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

4. Shell Programming and Scripting

Display top ten directories by size

Hi, I am new to Unix. I want to display top 10 folders by size. I tried with du -ksl * | sort -nr | head -10 command .But I am getting the following error -bash: /usr/bin/du: Argument list too long Can some one help me. Thanks. (5 Replies)
Discussion started by: Satyak
5 Replies

5. UNIX for Dummies Questions & Answers

Maximum size of a file in unix

What's the maximum file size supported by unix. (3 Replies)
Discussion started by: nagalenoj
3 Replies

6. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

7. UNIX for Dummies Questions & Answers

top ten utilities in shell scripting?

Let's get some feedback about the top ten ute's you guys use in writing your scripts - I mean yeah it depends on the job and what you're trying to accomplish, but there ARE those commands (sed, grep, awk, cut, etc.) that most will use time and again... ...so, what do you use? (3 Replies)
Discussion started by: diego
3 Replies
Login or Register to Ask a Question