Find command size greater than or equalto

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Find command size greater than or equalto
# 1  
Old 07-18-2017
Find command size greater than or equalto

How do I find the files greater than or equal to a given size using find command.

find ./ -size +0k   --> Lists files greater than 0K

find ./ -size 0k --> Lists the file size equal to 0K.

I have other conditions to check, hence using find command.

Thanks in advance.
# 2  
Old 07-18-2017
Your example is a bit odd. *All* files have a size 0 or greater.
To find files that are greater or equal than 10k you can negate it, "not smaller than 10k"
find . \! -size -10k

This is more efficient than an or condition
find . \( -size 10k -o -size +10k \)

# 3  
Old 07-18-2017
I have a purge script. Based on the Input parameter, the script has to find and delete the files greater than or equal to the nkb. For now, I am using the or condition as you mentioned above.

# 4  
Old 07-19-2017
I have a faint memory of find's size rounding methods being a bit strange on some systems. You might want to search these fora for the discussion of it.
# 5  
Old 07-19-2017
Would stat give you a getter output to work with? It gives you the output in a customisable format. Using ls or the -ls flag on find can cause issues if the file has a group name with spaces, for example:-
# stat bigfile
  File: `bigfile'
  Size: 6762219520	Blocks: 13207472   IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 2359475     Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  500/rbatte1)   Gid: (  500/rbatte1)
Access: 2017-07-19 12:23:40.597780337 +0100
Modify: 2017-07-19 12:27:58.730711684 +0100
Change: 2017-07-19 12:28:17.474415803 +0100

It might not be neat, but if you use find to get a list of files based on whatever other criteria you have, you can then work through the list with some simple tests for file size, a bit like this:-
while read listed_file
   listed_file_size="$(stat -c%s${listed_file})
   if [ ${listed_file_size} -gt 10240 ]
      echo "File ${listed_file} is greater than 10K at ${listed_file_size} bytes."
done < /tmp/file_list

Of course, you could substitute an input file for the output of your find command.

If you are looking for files over a certain size, then another option might be to call stat from your find with xargs, perhaps:-
find /path/to/search -type f any other options | xargs stat -c '%s %n' | sort -n

This will give you the files in size order, so once you have the first file that exceeds your limit, you can assume that all the others will too.

What is the full criteria of your search and what actions do you want to take? It would be useful to show us the output from uname -a too.

Thanks, in advance,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

find command to display size and date of a file

Hi, The blow code does not yeild any output. find . -name "*.jar" -o -name "*.ksh" -o -name "*.properties" -name "*.war" -o -name "*.ear" -o -name "*.sh" -o -name "*.cfg" -exec ls -l {} \; I wish to print the filename filesize filedate in HP-UX. Can anyone help ? (9 Replies)
Discussion started by: mohtashims
9 Replies

2. Shell Programming and Scripting

Unix file empty.. but size is greater than zero??/

Hi, I have a file by redirecting some contents in unix shell. Even when there is no content that is being redirected, the file size still shows greater than zero. but even if there is no matching pattern the file APPRES has size greater than 0bytes. awk -f AA.awk $logfile>APPRES... (3 Replies)
Discussion started by: justchill
3 Replies

3. Shell Programming and Scripting

shell script to check file size greater than 50M

Hi All, OS:AIX 64 bits using korn shell. Requirement: shell script to check file size greater than 50M and send mail alert. Thanks for your time! Regards, (3 Replies)
Discussion started by: a1_win
3 Replies

4. UNIX for Advanced & Expert Users

Find command -size option limitation ?

Hi All, I ran code in test environment to find the files more than 1TB given below is a snippet from code: FILE_SYSTEM=/home/arun MAX_FILE_LIMIT=1099511627776 find $FILE_SYSTEM -type f -size +"$MAX_FILE_LIMIT"c -ls -xdev 2>/dev/null | while read fname do echo "File larger than... (3 Replies)
Discussion started by: Arunprasad
3 Replies

5. Shell Programming and Scripting

Filter the file list greater then the size specified by user

HI, Can any tell me how to filter the list of files greater than the size specified by user. The size should be provided by user as an input. Regards shiva (6 Replies)
Discussion started by: shivu
6 Replies

6. Shell Programming and Scripting

Command/script to find size of Unix Box ?

Please could anyone provide me the Command/script to find the size and usage of Unix box ASAP ? (6 Replies)
Discussion started by: sakthifire
6 Replies

7. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

8. UNIX for Dummies Questions & Answers

command(s) to find size of mysql database?

hello, i'm trying to figure out the size of a mysql database shelling into my server with putty / command line. is there / are there any commands that will return the size of a database, in MB? thanks. (4 Replies)
Discussion started by: sbourgeois
4 Replies

9. Shell Programming and Scripting

Can I find wether a particular file exist and size greater than please

Can I find wether a particular file exist and size greater than zero in one line command. similar to this if && something in one if test .... e.g. if 1.) is it possible ? ... if yes how 2.) what would be the return type in case there is success or failure. I mean if both are... (4 Replies)
Discussion started by: guhas
4 Replies

10. Shell Programming and Scripting

File size greater than 0

ok I want to know how to touch a file and find out that it is greater than 0 then if it is not I want to fail the job other wise I want to success amnd go on. Can anyone help. Thanks Shannon Kammer (1 Reply)
Discussion started by: skammer1234
1 Replies
Login or Register to Ask a Question

Featured Tech Videos