LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-02-2016, 06:18 AM   #1
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 14 & 15
Posts: 73

Rep: Reputation: Disabled
Greater than and Equal too in script


If I wanted to find and execute a command for files over 1 gig in size I could use:

Code:
find /folder/ -type f -size +1G -exec stuff
To find smaller than 1 gig I would change the +1G to -1G.
However, how would I put the argument for greater than and equal too?

Regards
Tim
 
Old 09-02-2016, 06:56 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
It's highly unlikely you'd have files that are EXACTLY 1G in size, but if you really want to you could use:

Code:
find /folder/ -type f -size +1073741823c -exec stuff
 
1 members found this post helpful.
Old 09-02-2016, 07:15 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
By using not or two expressions. Not less then 1G is the same as >=1G or you can search for both equal 1G and greater then 1G.

Code:
find /folder/ -type f ! -size -1000M -exec stuff
or
Code:
find /folder/ -type f -size 1G -o -size +1G -exec stuff

Last edited by michaelk; 09-02-2016 at 03:53 PM.
 
3 members found this post helpful.
Old 09-02-2016, 07:20 AM   #4
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 14 & 15
Posts: 73

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
By using not or two expressions. Not less then 1G is the same as >=1G or you can search for both equal 1G and greater then 1G.

Code:
find /folder/ -type f ! -size -1G -exec stuff
or
Code:
find /folder/ -type f -size 1G -and -size +1G -exec stuff
perfect, thanks.
 
Old 09-02-2016, 10:32 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,957

Rep: Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267
Quote:
Originally Posted by michaelk View Post
By using not or two expressions. Not less then 1G is the same as >=1G or you can search for both equal 1G and greater then 1G.

Code:
find /folder/ -type f ! -size -1G -exec stuff
or
Code:
find /folder/ -type f -size 1G -and -size +1G -exec stuff
Sorry, but "-size 1G" does not do what you think it does. Think of it as, "How many units of this size are needed to hold this file?" A file which has a size from 1 byte to 1073741824 bytes (inclusive) "uses" a single 1G unit, and "-size 1G" would match that file.

Also, it is logically impossible for a file's size to be both exactly 1G and greater than 1G. You need to use OR.
Code:
find /folder/ -type f \( -size 1073741824c -o -size +1G \) -exec stuff
Which is equivalent to
Code:
find /folder/ -type f -size +1073741823c -exec stuff
 
Old 09-02-2016, 11:04 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Oops, you correct it should be or (-o)

Last edited by michaelk; 09-02-2016 at 11:10 AM.
 
Old 09-02-2016, 12:24 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,957

Rep: Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267
Also,
Code:
find /folder/ -type f ! -size -1G
is not what is wanted here since it will select everything except zero-length files.
 
Old 09-02-2016, 12:29 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Hmm...

Ok then in that case use 1000M

folder contests
104857600 Sep 2 13:58 f100M
1073741824 Sep 2 11:36 f1g
262144000 Sep 2 14:33 f250m
2147483648 Sep 2 11:37 f2g
536870912 Sep 2 11:35 f512m
786432000 Sep 2 14:39 f750m

find . -type f ! -size -1000M
./f2g
./f1g

Last edited by michaelk; 09-02-2016 at 03:58 PM. Reason: Update
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: With greater permissions, comes greater responsibility LXer Syndicated Linux News 0 02-20-2014 04:11 PM
[SOLVED] !=~ is equal to =~ ?? perl script acting unusual knockout_artist Linux - Newbie 2 04-12-2010 02:56 AM
bash script for listing all users with emails greater than 100mb evil_empire Linux - Newbie 3 09-04-2009 01:27 PM
Shell script - Pass command options with equal sign fabdog Linux - Newbie 5 02-13-2009 07:32 AM
use greater than or equal to operators on a file/output shabev Linux - Enterprise 3 03-25-2008 03:09 PM


All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration