Operating System - HP-UX
1827808 Members
3082 Online
109969 Solutions
New Discussion

Re: finding out large file and directory

 
SOLVED
Go to solution
sekar_1
Advisor

finding out large file and directory

Admins,
i have to find out the large file and directory. i searched in our ITRC and almost all the "find" commands gives many "find: cannot open /var/opt/xyz.." which i like to discard.

or
how to find out the 10 largest files in current directory??

11 REPLIES 11
Pete Randall
Outstanding Contributor

Re: finding out large file and directory

try this:

du -sk * |sort -n |tail -10


Pete

Pete
Geoff Wild
Honored Contributor

Re: finding out large file and directory

find / somefile 2>/dev/null

that will not display "find: cannot open"

add -size option to find files bigger then a certain size.

man find for details...


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
john korterman
Honored Contributor

Re: finding out large file and directory

Hi,

try this:

ls -l| sort -nrk5| head -10

regards,
John K.
it would be nice if you always got a second chance
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: finding out large file and directory

To get rid out the cannot open message simply redirect stderr to /dev/null.

find . -type f -exec ls -l {} \+ 2>/dev/null | sort -k n5,5 | tail -n 10

If it ain't broke, I can fix that.
Geoff Wild
Honored Contributor

Re: finding out large file and directory

find /usr -size +10240c 2>/dev/null


that will list all files bigger then 10240 bytes...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
James R. Ferguson
Acclaimed Contributor

Re: finding out large file and directory

Hi:

# du -xk|sort -rnk1,1|head -11

...will show the top-10 *directories* in 1k blocks

# find /path -xdev -type f -exec ls -l {} + 2> /dev/null | sort -knr5,5 | head -10

...will find 10-largest *files* in the directory /path discarding any STDERR messages from 'find'.

Regards!

...JRF...
sekar_1
Advisor

Re: finding out large file and directory

thanks for ur reply.

find /var/opt/ -type f -exec ls -l {} \+ 2>/dev/null | sort -k n5,5 | tail -n 50
this command gives exactly what i want.

still, to drill down the required result,
i would like not searching in some paths..say "/var/opt/bin/" inside this i dont want to "find"

in other words, lets think like i have to find large files in / while excluding /bin/ , /stand and /sbin

thanks a lot admins..
Dennis Handly
Acclaimed Contributor

Re: finding out large file and directory

>i would like not searching in some paths. say "/var/opt/bin/" inside this i don't want to "find"

You can use:
find /var/opt/ ! -path "/var/opt/bin/*"

And just repeat for more directories.

(There is no /bin/, it's just a link, so you need to exclude /usr/bin/.)
James R. Ferguson
Acclaimed Contributor

Re: finding out large file and directory

Hi (again) Sekar:

> lets think like i have to find large files in / while excluding /bin/ , /stand and /sbin

First, if you are gonig to start with '/' you probably want to add the '-xdev' switch so that you do *not* visit mountpoints:

# find / -xdev -type f ...

Since '/bin' is a symbolic link to '/usr' this will eliminate visiting that directory. As for skipping '/stand' and '/sbin' do:

# find / -xdev -type f ! -path "/sbin/*" -a ! -path "/stand/*"

THUS, in all:

# find / -xdev -type f ! -path "/sbin/*" -a ! -path "/stand/*"
-exec ls -l {} + 2> /dev/null | sort -knr5,5 | head -10

Regards!

...JRF...
tsf_1
Frequent Advisor

Re: finding out large file and directory

Few examples below to find files larger/equal to certain size, use -xdev to restrict to only this directory. This example trying to find huge files in root directory:

# find / â xdev â size +3145728c (To list >=3MB)
# find / -xdev -size +8388608c (To list >=8MB)
# find / -xdev -size +10485760c (To list >=10MB)
# find / -xdev -size +104857600c (To list >=100MB)
# find / -xdev -size +1073741824c (To list >=1GB)
be willing to do, be happy to bear
sekar_1
Advisor

Re: finding out large file and directory

thanks a lot for all..