Quite often you need to make changes to the files with known names, but unknown location in your system. Sometimes you’re simply looking for a file but can only partially remember its name. In these and many other situations, find command is your friend.
Linux find Command
In case you’re looking for a way to find a specific command in Linux, please have a look at the following: apropos and whatis.
For examples of using the find command in Unix and Linux, please continue reading.
Basic find command usage
The easiest form of the find command needs no additional parameters, and you get a full list of files and directories in your current directory:
$ cd /tmp
$ find
.
./uname.txt
./.X11-unix
./.ICE-unix
Of course, find isn’t limited to searching for files in your current directory, and you can easily specify which directory you want find to go through:
Slightly more advanced form of using find allows you to specify which types of files you’re interested in. As you remember, there are quite a few file types in Unix, and you can narrow your search to match exactly the type of files you’re interested in.
Here’s an example showing how to find all the symbolic links under a certain directory, /etc in this case:
As you can see, /etc/X11/xkb is a symbolic link pointing to ../../usr/X11R6/lib/X11/xkb file.
Advanced find command techniques
This section of the page will be updated from time to time, so be sure to come back to find out more!
Find files which belong to a certain Unix user
Using the -user option, you can use find command to locate all the files belonging to a certain user. In this example, I’m searching for the files which belong to a system account called rpm under the /usr/bin directory:
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!