A method to find files on a Linux system is with the well named find command, find allows for certain parameters to be passed allowing for a more specialized and refined search.
find can also be used to execute commands on the returned files.
Simply finding a file by its case sensitive name:
find -name index.php
For the search to not be case sensitive:
find -iname readme.txt
Searching by type;
Find files that are of a certain extension:
find / -type f -name "*.log"
Search filtering can be done by size too;
All MP4 files greater than 1 Gigabyte:
find / -type f -name "*.mp4" +1G
All MP4 files less than 20 Megabytes:
find / -type f -name "*.mp4" -20M
Time filtering is based around 3 methods:
Finding files accessed less than a week ago:
find / -atime -7
Finding with modification time of less than 1 day:
find / -mtime -1
All these commands and filters can be combined to help narrow down or even widen your search.
An example for doing something with the “found” files is this:
find /tmp -type f -name "*.log" -mtime +7 -exec rm -f {} \; This will delete all the .log files in /tmp that were created over 1 week (7 days) ago.
View the official find docs here or a comprehensive guide here.
A drained and empty Kennington reservoir images from a drone in early July 2024. The…
Merrimu Reservoir from drone. Click images to view larger.
Some early September spring shots from a bushwalk, It is still too early for wildflowers.
I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…
If you ever needed a simple solution in Laravel to delete an entire directory and…
How to enforce only one user to register or be registered in a Laravel web…