Finding files in linux by size

Linux: Find files larger than given size (gb/mb/kb/bytes)

In this article, we will discuss how to recursively find files which are larger than a given size in Linux, using the find command.

Table of Contents

Many times we encounter a situation where we need to find huge files in Linux. These files can be log files or some other kind of data files. In such scenarios we need to search files by size. For this, we can easily use the find command in Linux.

The find command in Linux provides an easy way to search files recursively in a directory hierarchy. It also provides various options to do the selective search. One such option is “-size”, it helps to recursively search files by size.

Syntax of find command to find files bigger than given size in Linux

In the given , it will recursively search for the files whose size is greater than N. Here N is a number and along with it we can specify size unit type like,

Frequently Asked:

For example, “-size +4G” makes the find command to search for files greater than 4GB. Here, + sign is denote that look for files greater than or equal to N[Type], like in this case, -size +4G will make find command to look for files bigger than 4GB.

Let’s see some detailed examples of finding files greater than a given size,

Find files larger than 4gb in Linux

To find files larger than 4GB, we need to pass the -size option with value +4G in the find command.

/usr/logs/test_1_logs.txt /usr/logs/test_2_logs.txt

It recursively searched for files inside the folder “/usr” and filtered out the files with size larger than or equal to 4GB, then printed the paths of such files.

The previous command just printed the file paths which are greater than 4GB. If you want print the size along with file name then use this command,

find /usr -type f -size +4G -exec ls -lh <> \; | awk '< print $9 "|| Size : " $5 >'
/usr/logs/test_1_logs.txt|| Size : 4.6G /usr/logs/test_2_logs.txt|| Size : 7.2G

Find files larger than 1gb in Linux

To find files larger than 1GB, we need to pass the -size option with value +1G in the find command.

/usr/logs/error_logs.txt
/usr/logs/warning_logs.txt

It recursively searched for files inside the folder “/usr/” and filtered out the files with size larger than or equal to 1GB, then printed the paths of such files.

The previous command just printed the file paths which are greater than 1GB. If you want print the size along with file name then use this command,

find /usr -type f -size +1G -exec ls -lh <> \; | awk '< print $9 "|| Size : " $5 >'
/usr/logs/error_logs.txt|| Size : 1.6G /usr/logs/warning_logs.txt|| Size : 2.2G

Find files larger than 500mb in Linux

To find files larger than 500 MB, we need to pass the -size option with value +500M in the find command.

find /usr -type f -size +500M

It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 500MB, then print the paths of each such files.

/usr/logs/test_3_logs.txt /usr/logs/test_4_logs.txt

To print file size along with with file paths for files larger than 500MB use this command,

find /usr -type f -size +500M -exec ls -lh <> \; | awk '< print $9 "|| Size : " $5 >'

It will print the file paths along with size for the files larger than 500MB.

/usr/logs/test_3_logs.txt|| Size : 610G /usr/logs/test_4_logs.txt|| Size : 712G

Find files larger than 100mb in Linux

To find files larger than 100 MB, we need to pass the -size option with value +100M in the find command.

find /usr -type f -size +100M

It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 100MB, then print the paths of each such files. To print file size along with with file paths for files larger than 100MB use this command,

find /usr -type f -size +100M -exec ls -lh <> \; | awk '< print $9 "|| Size : " $5 >'

It will print the file paths along with size for the files larger than 100MB.

Читайте также:  Linux list installed packages version

Find files larger than 50mb in Linux

To find files larger than 50 MB, we need to pass the -size option with value +50M in the find command.

It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 50MB, then print the paths of each such files. To print file size along with with file paths for files larger than 50MB use this command,

find /usr -type f -size +50M -exec ls -lh <> \; | awk '< print $9 "|| Size : " $5 >'

It will print the file paths along with size for the files larger than 50MB.

Find files larger than 0 bytes in Linux

To find files larger than 0 Bytes, we need to pass the -size option with value +0b in the find command.

It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 0 Bytes, then print the paths of each such files. To print file size along with with file paths for files larger than 0 Bytes use this command,

find /usr -type f -size +0b -exec ls -lh <> \; | awk '< print $9 "|| Size : " $5 >'

It will print the file paths along with size for the files larger than 0 bytes.

Leave a Comment Cancel Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Terms of Use

Disclaimer

Copyright © 2023 thisPointer

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Читайте также:  Deny user access linux

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.

The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.

The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.

The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.

Источник

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.

Читайте также:  Удалить ненужные пакеты линукс

Источник

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 !

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 

Источник

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