Use Find and Locate to Search for Files in Linux
Learn On Demand
Learn On Demand Pro Series

Time
1 hour
Difficulty
Intermediate

This IT Pro Challenge hands-on lab teaches you how to search for files in several different ways using both name and file size. You will become familiar with using the find, locate, whereis, and which commands to find files, find text within files, find files of a certain type, and open those files.

Start your free 3-day trial and become one of the 3 million Cybersecurity professionals advancing their career goals

Sign up with
Or

Already have an account? Sign In »

This Learn On Demand Pro Series is part of a Career Path: Become a Network Engineer

Overview

In this IT Pro Challenge, you will use the find, locate, whereis, and which commands to search for files on a drive, a string contained in the files, and files of a particular type. You will also learn how to search for and launch a file in a text editor and locate all files associated with an executable. Throughout the lab, you will use User commands, Manual Pager Utility commands, System Manager's Manual commands, and General Manual commands. The skills acquired in this lab are useful for a career as a network or system administrator.

Overview

The scenario for this hands-on lab is that you are a system administrator of a Linux file server, and you need to search for files using criteria like name and file size. To do this, you will use the find command to search for files on a drive directly. Then you will use an index database to search for files using the locate command. Finally, you will use the whereis and __which __commands to search for information.

The whereis command allows you to search Unix and Linux systems for binary, source, and manual page files. The which __command (which is similar to the Unix __type command) allows you to find the location of executable files.

Search for files by using the find command

First, you need to use the touch command to create a file (EmployeeList.txt) and then use the dd if=/dev/zero of=file.txt count=50 bs=1MB command to create a 50 MB file in the root directory.

Now you are going to use the find __command to search different directories for different things. You will search for files by name (Ex: __find [directory] -type f [search string] [file]), by owner (Ex: find [directory] -user [username], and by size (Ex: find [directory] -size +[file size]).

You will also search for a file by name and open it in a text editor (Ex: find [directory] -iname [filename.txt] -exec nano '{}' ;), and search for a file by name and view the file permissions (Ex: find [directory] -iname [filename.txt] -exec ls -l ‘{}’ ;).

Search for files by using the locate command

Now you will use the touch command to create three .jpg files (image1, image2, image3) in the root user's home directory.

Then you will run the updatedb __command to update the __mlocate database. Then you will use the locate __(Ex: __locate -i [directory] [filetype]) command to search for .jpg files on the entire drive and in the root user's home directory and you will search for the total number of files in a directory.

Search for information about the date command by using the whereis and which commands

Finally, you will use the whereis date command to display the supporting files for the date command. Then you will use the which date command to display the location of the date command executable file.

Summary Conclusion

By taking this hands-on lab, you will learn how to search for information in several different ways in Linux. You will use the find command to search the hard drive for information, use the locate command to update the mlocate database, and use the whereis and which commands to display information about the date command executable file.

Comprehensive Learning

See the full benefits of our immersive learning experience with interactive courses and guided career paths.

LEARN MORE. ACHIEVE MORE.

Follow A Path

Deciphering the essentials to enter a new career is hard, so we did it for you!

Focus on building your skills and take this learn on demand pro series in a guided Career Path.

LEARN MORE. ACHIEVE MORE.

Follow A Path

Deciphering the essentials to enter a new career is hard, so we did it for you!

Focus on building your skills and take this learn on demand pro series in a guided Career Path.