Page 166 - DCAP106_OPERATING_SYSTEM_TOOLS
P. 166
Unit 9: The File System
Regular Find Patterns Notes
The most simple find construct is to locate a particular file inside one or more directories.
Example: To find files or directories inside /etc whose name is dhcpd.conf (exact
matches):
$ find /etc -name dhcpd.conf
/etc/dhcp/dhcpd.conf
To find files (not directories) where dhcpd is in the filename, also inside /etc directory:
$ find /etc -type f -name ‘*dhcpd*’
/etc/conf.d/dhcpd
/etc/init.d/dhcpd
/etc/udhcpd.conf
/etc/dhcp/dhcpd.conf
To find files in the /etc directory who have been modified within the last 7 days (read: “less than
7 days ago”):
$ find /etc -type f -mtime -7
/etc/mtab
/etc/adjtime
/etc/wifi-radar.conf
/etc/genkernel.conf
You can even find files based on their ownership.
For example, find the files in /etc that do not belong to the root user:
$ find /etc -type f -not -user root
Combining Find Patterns
You can also combine find patterns.
Example: Find files modified within the last 7 days but whose name does not contain
.conf:
$ find /etc -type f -mtime -7 -not -name ‘*.conf’
/etc/mtab
/etc/adjtime
Or, find the same files, but the name should also not be mtab:
$ find /etc -type f -mtime -7 -not \( -name ‘*.conf’ -or -name mtab)
/etc/adjtime
Working with the results
With find, you can also perform tasks on the results.
Example: To view the “ls -l” output against the files that find finds, you can add the -exec
option. The string after -exec should contain two special character sequences:
LOVELY PROFESSIONAL UNIVERSITY 159