This post will cover topic related to find command particularly about ‘Search for Files with Case-Insensitive Pattern Matching Using -ilname in find’ with multiple find command examples and different find command scenerios. So this find command article will help you to understand find command and options available in it. End of the post, you will have better understanding of find command and how to use find command in better way.
The find
command is a powerful tool for searching files and directories in Unix-like operating systems. The -ilname
option is particularly useful for performing a case-insensitive search for files based on a specified pattern. This option allows you to locate files regardless of their case, which can be helpful when you are unsure of the exact casing used in filenames.
Here are some examples demonstrating how to use the -ilname
option with the find
command:
Example 1: find /home/user -ilname "*.txt"
This command searches the directory /home/user
and all its subdirectories for files with a .txt
extension, ignoring case. It will match files like Document.TXT
, notes.Txt
, and report.tXTs
.
Output:
/home/user/Document.TXT /home/user/notes.Txt /home/user/subdir/report.tXTs
Example 2: find /var/log -ilname "error*"
This command searches the /var/log
directory for files that start with error
, regardless of the case. It will find files such as Error.log
or ERROR_BACKUP.log
.
Output:
/var/log/Error.log /var/log/ERROR_BACKUP.log
Example 3: find /etc -ilname "*.conf"
This searches for configuration files with a .conf
extension in the /etc
directory, ignoring the case of the file extension.
Output:
/etc/ssh/sshd_config /etc/apache2/extra/httpd.conf
Example 4: find /home/user -ilname "photo*"
Finds all files starting with photo
in the /home/user
directory, irrespective of the casing. Matches might include Photo1.jpg
, PHOTOS_2023.png
.
Output:
/home/user/Photo1.jpg /home/user/PHOTOS_2023.png
Example 5: find /usr/local/bin -ilname "script.sh"
Looks for files named script.sh
in the /usr/local/bin
directory, regardless of how the case is used in the file name.
Output:
/usr/local/bin/Script.SH /usr/local/bin/SCRIPT.SH
Example 6: find /opt -ilname "README*"
This searches the /opt
directory for any files beginning with README
, regardless of case sensitivity.
Output:
/opt/README.md /opt/ReadMe.txt
Example 7: find /mnt -ilname "*backup*"
Finds files containing the word backup
in their names within the /mnt
directory, ignoring case.
Output:
/mnt/BackupFile.bak /mnt/BackUp_2023.tar
Example 8: find /srv -ilname "*.log"
Locates log files with a .log
extension in the /srv
directory, irrespective of the case of the extension.
Output:
/srv/access.log /srv/ERROR.LOG
Example 9: find /tmp -ilname "*temp*"
Searches for files containing temp
in their names within the /tmp
directory, ignoring the case.
Output:
/tmp/tempfile.txt /tmp/TEMPORARY_DATA.dat
Example 10: find /home/user/docs -ilname "report*2024*"
Finds files starting with report
and containing 2024
in their names within the /home/user/docs
directory, regardless of case.
Output:
/home/user/docs/Report_2024_summary.pdf /home/user/docs/REPORT_2024_Final.docx
To verify the commands executed correctly, follow these steps:
- Run the command in your terminal and observe the output.
- Check the paths listed in the output to ensure they match the expected results.
- If no output is returned, confirm that the pattern used in the command matches any files in the specified directory.
- Review the file names and paths to ensure they are correctly listed and match the search pattern provided.
Also check similar articles.
Find Files by Group Name with -group in find Command
Locate Files by Group ID Using -gid in find Command
How to Search for Filesystems with -fstype in find Command
Use -false to Test Conditional Expressions in find Command
Efficiently Find Empty Files and Directories with -empty in find
Discussion about this post