Operating System - HP-UX
1834149 Members
2319 Online
110064 Solutions
New Discussion

shell programming -> find files by size

 
SOLVED
Go to solution
Christian Marquardt_1
Regular Advisor

shell programming -> find files by size

Hello,
I need to write a script to find all files with a size between 1,8 GB and 2 GB and discover the type of filesystem they reside to.
Can anyone help me get an idea how to do???

regards
Christian
7 REPLIES 7
RAC_1
Honored Contributor
Solution

Re: shell programming -> find files by size

find /dir_to_search -type f -exec ll -d {} \;| grep -v '^total' | awk '{if($5+0>100000000 || $5+0>800000000 || $5+0>200000000)print $0}'
There is no substitute to HARDWORK
Peter Godron
Honored Contributor

Re: shell programming -> find files by size

Christian,
find . -size +1800000c > /tmp/a.lis
find . -size +2000000c > /tmp/b.lis
sdiff -s /tmp/a.lis /tmp/b.lis
Steven E. Protter
Exalted Contributor

Re: shell programming -> find files by size

Shalom,

A start.

cd /

du -k | sort -rn | more

That will show you where the big files are.

Then you get to use the find command

see the parameters size -n (in blocks)

Example

find / -local -size +50 -print

Adjust the size to come up with your list.

The command will list the filesystem.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: shell programming -> find files by size

Hi Christian:

Using 'find' to select files whose sizes fall into the range you seek is simple, as already mentioned. 'find' has all of the necessary logic to limit the ranges thusly:

# find /tmp -xdev -size +100 -a -size -200 | xargs ls -l

The above example would find all files in '/tmp' whose (c)haracter size was more than 100 and less than 200 characters. That differentiation is done siwht the + and - operands before the size. The manpages for 'find' describe more details.

To determine the *type* of filesystem in which your directory resides, you can use 'fstyp' on its special device file. Most usually, today, the filesystem is going to be 'vxfs'.

The use of 'xdev' in the above 'find' prevents 'find' from crossing mountpoints. You can also instruct 'find' to confine its returned files to specific filesystem types (CDFS, HFS or NFS) by using the '-fstype' argument to 'find'. See again, the manpages for more information.

Regards!

...JRF...
Raj D.
Honored Contributor

Re: shell programming -> find files by size

Hi Christian Marquardt ,

Use this command to list all files from size largest first :

# ls -lR | sort +4 -5nr | more

Hope this will help ,
Cheers,

Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: shell programming -> find files by size

You can also use the find command with xdev , to search that mountpint ,as given above postings.

hth,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Arturo Galbiati
Esteemed Contributor

Re: shell programming -> find files by size

Hi,
you can use:
cd
find . -type f 2>/dev/null | xargs ll|awk '$5>1932735283&&$5<=2147483648'

It works on HP-UX 11i.

HTH,
ART