I want to find files which are greater than 1 GB and older than 6 months in entire server. How to write a command for this?
Asked
Active
Viewed 9.8k times
2 Answers
68
Use find
:
find /path -mtime +180 -size +1G
-mtime
means search for modification times that are greater than 180 days (+180). And the -size
parameter searches for files greater than 1GB.

chaos
- 48,171
12
find / -size +1G -mtime +180 -type f -print
Here's the explanation of the command option by option: Starting from the root directory, it finds all files bigger than 1 Gb, modified more than 180 days ago, that are of type "file", and prints their path.

dr_
- 29,602
find
implementations where thatG
suffix is supported, it means GiB (1073741824 bytes), not GB (1000000000). Portably, you'd usefind /path -mtime +180 -size +1073741824c
– Stéphane Chazelas May 13 '15 at 12:11find: a.txt :Permission denied
I suggest adding this2>/dev/null
inspired from this comment: https://unix.stackexchange.com/questions/42841/how-to-skip-permission-denied-errors-when-running-find-in-linux#comment58845_42842 – gmansour Feb 10 '18 at 03:24xargs ls -lhS
to sort them by size:
– user553965 Jan 29 '19 at 19:46find /path -mtime +180 -size +1G | xargs ls -lhS
find / -size +1G -mtime +180 -print0 2>/dev/null | xargs -0 ls -lhS
. Newbies note: The redirection of2>/dev/null
just gets rid of thepermission denied
errors which will inevitably appear when searching from root. To sort by last modified date usels -lht
instead and addingr
to thels
commands, e.g.ls -lhSr
, will reverse the results (smallest to largest / oldest to newest). – mattst Oct 25 '19 at 15:21