19

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?

36

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.

  • 1
    Note that in the find implementations where that G suffix is supported, it means GiB (1073741824 bytes), not GB (1000000000). Portably, you'd use find /path -mtime +180 -size +1073741824c – Stéphane Chazelas May 13 '15 at 12:11
  • if you want to avoid seeing errors between the list of files like these: find: a.txt :Permission denied I suggest adding this 2>/dev/null inspired from this comment: unix.stackexchange.com/questions/42841/… – gmansour Feb 10 '18 at 3:24
  • You can also pipe the results into xargs ls -lhS to sort them by size: find /path -mtime +180 -size +1G | xargs ls -lhS – user553965 Jan 29 at 19:46
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.