How can I find all the files in directory greater than a certain size, say, 15 KB, and which have been modified in the last 10 days?
Asked
Active
Viewed 6,547 times
-4
2 Answers
5
I'd do it like this:
find /directory -mtime -10 -size +15k
The /directory
is the base directory where the search is preformed (recursively by default).
-mtime 10
means it will look for files modified in the last 10 days:
-mtime n File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modi- fication times.
-size 15k
means it will look for files larger than 15 kilobytes:
-size n[cwbkMG] File uses n units of space, rounding up. The following suffixes can be used:
`b' for 512-byte blocks (this is the default if no suffix is used) `c' for bytes `w' for two-byte words `k' for Kilobytes (units of 1024 bytes) `M' for Megabytes (units of 1048576 bytes) `G' for Gigabytes (units of 1073741824 bytes) The size does not count indirect blocks, but it does count blocks in sparse files that are not actually allocated. Bear in mind that the `%k' and `%b' format specifiers of -printf handle sparse files differently. The `b' suffix always denotes 512-byte blocks and never 1 Kilobyte blocks, which is different to the behaviour of -ls. The + and - prefixes signify greater than and less than, as usual, but bear in mind that the size is rounded up to the next unit (so a 1-byte file is not matched by -size -1M).
If this is a homework question of some kind, please read the find(1)
manual for your operating system by typing man find
on your system, and really learn how it's working.

Will
- 2,754
1
Since I know it's difficult for a neophyte to find out which Linux command can be used to obtain a specific result, I'll point you to the correct direction.
The command you need to use is find
.
Its manual page, which you can read via
man find
will give you all the info you need. From this point you can work alone.

dr_
- 29,602
find
seems a better tool, @OP: This is not a script writing (or a one-liner writing) service. We are happy to help you if you get stuck after spending some effort. But do try to solve this on your own first and include what you already tried in the post. You can add that using the edit link. – Hennes Jan 30 '16 at 14:52