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
# 8  
Old 02-14-2008
Quote:
Originally Posted by abhilashnair
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

Use "du -h", it will report the size in a human readable form.

However, this will make the sort a bit more complex.

To maintain the sort as it is, use "du -k" which reports in kbytes instead of blocks, meaning the output numbers will be half as big.
# 9  
Old 02-15-2008
Quote:
Originally Posted by sb008
Use "du -h", it will report the size in a human readable form.

However, this will make the sort a bit more complex.

To maintain the sort as it is, use "du -k" which reports in kbytes instead of blocks, meaning the output numbers will be half as big.
I'm not sure if I should start a new thread so if I'm posting inappropriately apologies.

Is there a way to get du -k * | sort -rn | head -11, which I prefer for some reason to the find above to recurse?

eg
if I have a file test.txt in . and dirb of the same size the above will report;
65100 test.txt
....
65100 dirb
...

I like the output of the find but find it to be more system intensive than the straight du but if I can't get du to work the same way I'll start to use it instead.
# 10  
Old 02-15-2008
Quote:
Originally Posted by Wolja
I'm not sure if I should start a new thread so if I'm posting inappropriately apologies.

Is there a way to get du -k * | sort -rn | head -11, which I prefer for some reason to the find above to recurse?

eg
if I have a file test.txt in . and dirb of the same size the above will report;
65100 test.txt
....
65100 dirb
...

I like the output of the find but find it to be more system intensive than the straight du but if I can't get du to work the same way I'll start to use it instead.

if you use "-type f" in the "find" command as posted earlier, it shouldn't bring up directories.
# 11  
Old 02-18-2008
Quote:
Originally Posted by sb008
if you use "-type f" in the "find" command as posted earlier, it shouldn't bring up directories.
Ah my bad I wasn't clear enough Smilie

with the -f limiting it to file names I get with the find , find $dir -type f -exec du -k {} \; 2>>/dev/null | sort -rn | head -${hd}

the following

480056 /somedir/test.txt
98911 /anotherdir/anotherfile.sh

Whereas with du -ks * | sort -rn |head -10 where I would prefer the same as the find above with the directories.
22016 temp_file
40000 bin ( a directory)

However while working out how to stop find recursing directories I answered my own question.

du -k * | sort -rn | head -10 gives the same answer as the find.


.
 
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