-name and -type look at what an item is. Two more tests look at how big it is and how old it is.
-size: bigger or smaller
Big files are measured in kilobytes and megabytes:
| Unit | Size |
|---|---|
k | Kilobyte: 1024 bytes |
M | Megabyte: 1024 kilobytes |
G | Gigabyte: 1024 megabytes |
| Test | Keeps items |
|---|---|
-size +100k | More than 100 kilobytes |
-size -100k | Less than 100 kilobytes |
text
learner@tidepool:~$ find ~/photos -type f -size +100k
/home/learner/photos/shop-front.jpgAdd -type f. A directory has a size too, often 4096 bytes, so -size +1k also finds directories.
-mtime: days since the last change
-mtime counts days since the last change of the item, the time that ls -l shows.
| Test | Keeps items that changed |
|---|---|
-mtime -2 | Less than 2 days ago |
-mtime +30 | More than 30 days ago |
-size +100k
biggermore than
-mtime +30
oldermore than 30 days ago
Put the tests together
text
learner@tidepool:~$ find ~/logs -type f -name "*.log" -mtime +30This writes the log files that did not change for more than 30 days. These are often the files to move to an archive.