find – search for files and directories
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:
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:
Use find to locate files by type
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:
If we were to confirm whether a certain file is indeed a symlink, it’s very easy to do so:
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:
And if I want to verify that rpm really is the owner of some file from this list, I can use the ls command:
See also
Basic commands in Unix
Advanced Unix commands
touch command
mkdir command
How To: find large directories in Unix/Linux
See also
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:
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:
Use find to locate files by type
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:
If we were to confirm whether a certain file is indeed a symlink, it’s very easy to do so:
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:
And if I want to verify that rpm really is the owner of some file from this list, I can use the ls command:
See also
Basic commands in Unix Advanced Unix commands touch command mkdir command How To: find large directories in Unix/Linux