[donotprint]
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | None |
Time | 1m |
find dir-to-look criteria what-to-do
OR
find [options] dir-to-look criteria what-to-do
In this example, search your $HOME for a file called hello.c:
find $HOME -name "hello.c" -print
This will search the whole $HOME (i.e. /home/username/) system for any files named “hello.c” and display their pathnames:
/Users/vivek/Downloads/hello.c /Users/vivek/hello.c
However, it will not match HELLO.C or HellO.C. To match is case insensitive pass the -iname option as follows:
find $HOME -iname "hello.c" -print
Sample outputs:
/Users/vivek/Downloads/hello.c /Users/vivek/Downloads/Y/Hello.C /Users/vivek/Downloads/Z/HELLO.c /Users/vivek/hello.c
Finally, pass the -type f option to only search for files:
find /dir/to/search -type f -iname "fooBar.conf.sample" -print find $HOME -type f -iname "fooBar.conf.sample" -print
A note about AIX/HP-UX and other old Unix-like systems
The -iname works either on GNU or BSD (including OS X) version find command. If your version of find command does not supports -iname, try the following syntax using grep command:
find $HOME | grep -i "hello.c" find $HOME -name "*" -print | grep -i "hello.c"
OR try
find $HOME -name '[hH][eE][lL][lL][oO].[cC]' -print
Sample outputs:
/Users/vivek/Downloads/Z/HELLO.C /Users/vivek/Downloads/Z/HEllO.c /Users/vivek/Downloads/hello.c /Users/vivek/hello.c
See also
- Solaris UNIX Case-Insensitive Find File Search
- See all find command examples from our /faq/ sections.
- Man pages – grep(1)
🐧 2 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
the locate command fines file on a system. adding -i has it ignore case
locate -i hello.c
However it will also find directories with the same name that can produce a long for something like “hello” to prevent this use something like this
locate -ir /hello.c$
That will locate a the exact but case insensitive filename “hello.c”
Thanks. Very useful. I also found that with the locate command, you can add a parameter -i to ignore case