Files greater than 1 GB and older than 6 months

90,411

Solution 1

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.

Solution 2

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.

Share:
90,411

Related videos on Youtube

shinek
Author by

shinek

Updated on September 18, 2022

Comments

  • shinek
    shinek over 1 year

    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?

  • Stéphane Chazelas
    Stéphane Chazelas about 9 years
    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
  • gmansour
    gmansour over 6 years
    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/…
  • user553965
    user553965 over 5 years
    You can also pipe the results into xargs ls -lhS to sort them by size: find /path -mtime +180 -size +1G | xargs ls -lhS
  • mattst
    mattst over 4 years
    @user553965 Your command won't work. What is actually needed to sort by size is: find / -size +1G -mtime +180 -print0 2>/dev/null | xargs -0 ls -lhS. Newbies note: The redirection of 2>/dev/null just gets rid of the permission denied errors which will inevitably appear when searching from root. To sort by last modified date use ls -lht instead and adding r to the ls commands, e.g. ls -lhSr, will reverse the results (smallest to largest / oldest to newest).
  • Gabriel Staples
    Gabriel Staples over 2 years
    How do you also make it print out the human-readable size of each thing found?
  • chaos
    chaos over 2 years
    @GabrielStaples: Good question, you should ask it.
  • Gabriel Staples
    Gabriel Staples over 2 years