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?
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.
2Note that in the
findimplementations where that
Gsuffix is supported, it means GiB (1073741824 bytes), not GB (1000000000). Portably, you'd use
find /path -mtime +180 -size +1073741824cMay 13, 2015 at 12:11
1if you want to avoid seeing errors between the list of files like these:
find: a.txt :Permission deniedI suggest adding this
2>/dev/nullinspired from this comment: unix.stackexchange.com/questions/42841/…– gmansourFeb 10, 2018 at 3:24
1You can also pipe the results into
xargs ls -lhSto sort them by size:
find /path -mtime +180 -size +1G | xargs ls -lhSJan 29, 2019 at 19:46
1@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/nulljust gets rid of the
permission deniederrors which will inevitably appear when searching from root. To sort by last modified date use
ls -lhtinstead and adding
ls -lhSr, will reverse the results (smallest to largest / oldest to newest).– mattstOct 25, 2019 at 15:21
How do you also make it print out the human-readable size of each thing found? Aug 26, 2021 at 3:01
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.