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.
Using FTP and PHP to get an array of file details such as size and…
Creating and using Laravel form requests to create cleaner code, separation and reusability for your…
Improving the default Laravel login and register views in such a simple manner but making…
Laravel validation for checking if a field value exists in the database. The validation rule…