Linux find size less

Find files of specified size using bash in Unix [closed]

That command gives me find: unknown predicate ‘-print.’ I presume the . isn’t really there. Precision is important.

Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask. Also see Where do I post questions about Dev Ops?

3 Answers 3

find . -size +10000k -exec ls -sd <> + 

If your version of find won’t accept the + notation (which acts rather like xargs does), then you might use (GNU find and xargs , so find probably supports + anyway):

find . -size +10000k -print0 | xargs -0 ls -sd 

or you might replace the + with \; (and live with the relative inefficiency of this), or you might live with problems caused by spaces in names and use the portable:

find . -size +10000k -print | xargs ls -sd 

The -d on the ls commands ensures that if a directory is ever found (unlikely, but. ), then the directory information will be printed, not the files in the directory. And, if you’re looking for files more than 1 MB (as a now-deleted comment suggested), you need to adjust the +10000k to 1000k or maybe +1024k , or +2048 (for 512-byte blocks, the default unit for -size ). This will list the size and then the file name. You could avoid the need for -d by adding -type f to the find command, of course.

Источник

How to find files within a size range?

Please suggest a way to find all the zip files which are more than 60 MB but less than 70 MB in size using the find command.

Welcome to Super User. We are not a script writing service. We expect users to tell us what they have tried so far (including any scripts they are using) and where they’re stuck so that we can help with specific problems. Questions that only ask for scripts are too broad and are likely to be put on hold or closed. Please read How do I ask a good question?.

Читайте также:  Linux системные вызовы fork

3 Answers 3

find -iname "*.zip" -size +$((60*1024*1024))c -size -$((70*1024*1024))c 

Do NOT use the abbreviations 60M and 70M as this will also exclude all files of size greater than 69MB including 69.001MB!

From the info documentation, section «Size»:

-- Test: -size n[bckwMG] True if the file uses n units of space, rounding up. . 

Meaning, 69.001 gets rounded up to 70 and thus gets excluded!

A perfect example is find . -size -1M which will only match files of size zero.

Yeah I’m experiencing this quirk now when trying to bucketize my video files. Some sizes just don’t fall into any bucket.

find -iname "*.zip" -size +60M -size -70M 

You can also use -o to get a disjunction, and \( … \) to group various matches.

The same as you mentioned, but with -a. This should work

find / -type f -size +100M -a -size -200M -exec du -sh <> \;

Things to consider: (1) I think your answer adds nothing new, because -a is the default operator, the other answer uses it implicitly. If your answer explained this behavior along with other parts of the find syntax, then it would be of some value. In my opinion for now it’s just an unnecessarily complex (why -exec du ?) general (no zip-related filter) alternative. (2) The other answer is a community wiki. It’s like an invitation to improve it instead of writing a concurrent answer; so if you really have something to add, the best thing to do is to edit the community wiki answer.

Источник

Linux Command , how to find files by size larger than x?

I’m trying to find files with size larger than «x» , ex: 32 bytes But what I found in ls —help was only ls -S , that just sort by size and not satisfied my demand I’m new to Linux , I’ve tried Google but I don’t know what keywords should I use to find answer , could somebody give me advice , thank you !

Читайте также:  Add script to path linux

Your question is not about programing but about linux command that would be better in serverfault.com. If you want to ask something about shell script please read this first. stackoverflow.com/help/mcve

4 Answers 4

Try to use the power of find utility.

Find files greater than 32 bytes:

Of course you could also ask for files smaller than 32 bytes:

And files with exact 32 bytes:

For files with 32 bytes or more:

Or not smaller than 32 bytes (the same as above, but written another way):

And files between 32 and 64 bytes:

And you can also apply other common suffixes:

If you get find: illegal option — i error, specify the folder to search in after find . Add a dot to find files in the current folder: find . -size +32k -size -64M

You can change 32 for the size you want. In this case, I used your example.

Both answers you two provided me are excellent 😀 But I think I will give @rslemos the best answer tag since he’s «1 minute earier» , but still thanks to you !

Explanation: Use unix command find Using -size oprator

The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the ‘primaries’ and ‘operands’) in terms of each file in the tree.

Solution: According to the documentation

-size n[ckMGTP] True if the file's size, rounded up, in 512-byte blocks is n. If n is fol- lowed by a c, than the primary is true if the file's size is n bytes (charac- ters). Similarly if n is followed by a scale indicator than the file's size is compared to n scaled as: k kilobytes (1024 bytes) M megabytes (1024 kilobytes) G gigabytes (1024 megabytes) T terabytes (1024 gigabytes) P petabytes (1024 terabytes) 

Usage: perform find operation with -size flag and threshold measurement arguments: more than(+)/less than(-), number(n) and measurement type (k/M/G/T/P).

Formula: find -size [+/-]

1.Greater Than — Find all files in my current directory (.) that greater than 500 kilobyte

2.Less Than — Find all files in my current directory (.) that less than 100 megabyte.

3.Range — Find specific file (test) in my current directory (.) that greater than 500 kilobyte less than 100 megabyte (500k-1000k)

find . -name "test" -size +500k -size -100M 

4.Complex Range with Regex Find all .mkv files in all filesystem (root /) that are greater than 1 gigabyte and created this month, and present info of them.

find / -name "*.mkv" -size +1G -type f -ctime -4w | xargs ls -la 

Источник

Читайте также:  Изменить яркость экрана линукс

How to grep on files less than a size and limit to extension [duplicate]

I want to recursively grep on all files in subdirectories with extension csv but select only those files that are less than 4M in size. Is this correct way to do?

find . -type f -size -4M | grep --include \*.csv 'pattern' 

This command selects all the files with .csv , basically doesn’t limit to less than 4M in size, although find alone correctly finds all files less than 4M.

1 Answer 1

First I’ll set up some fake data:

$ for fileno in ; do for line in ; do printf "%d,%d,%d,%d,%d,%d,%d,%d\n" $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM; done > ~/tmp/big-fake-$.csv; done $ for fileno in ; do for line in ; do printf "%d,%d,%d,%d,%d,%d,%d,%d\n" $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM; done > ~/tmp/small-fake-$fileno.csv; done 

Let’s verify it has the properties you’re interested in:

$ du -b tmp/*.csv 4528666 tmp/big-fake-1.csv 4529227 tmp/big-fake-2.csv 4529173 tmp/big-fake-3.csv 4528782 tmp/big-fake-4.csv 2263714 tmp/small-fake-1.csv 2264028 tmp/small-fake-2.csv 2264398 tmp/small-fake-3.csv 2265134 tmp/small-fake-4.csv 

Now let’s look for some kind of pattern in the smaller files:

$ find tmp/ -type f -iregex ".*\.csv" -size -4M -exec grep '1,1,1' <> + tmp/small-fake-3.csv:15361,2526,13438,1083,3224,13221,1,19248 

Naturally the grep here can take other flags, eg -l if you’re only interested in the filenames which contain the pattern you want.

The <> + you can think of as kind of a template for «insert a list of filenames discovered by find in place of the brackets.» Since Grep is happy to take a list of filenames rather than one at a time, this is superior to -exec grep ‘1,1,1’ <> \; , which would launch a new instance of Grep for every separate file, one at a time.

This -exec flag I believe is a GNU-ism and not available in other types of find . I think on other platforms they go with a find -print0 | xargs -0 type of pattern. (I’m sure someone will leave a comment elaborating on this.)

Источник

Оцените статью
Adblock
detector