File Location Utilities.docx - File Location Utilities 0:00-0:28 In this lesson we're going to review how to find files in the Linux file system If

File Location Utilities.docx - File Location Utilities...

This preview shows page 1 - 2 out of 23 pages.

File Location Utilities 0:00-0:28 In this lesson, we're going to review how to find files in the Linux file system. If you're like me, this is a useful skill to have, because I create files all the time and then can't remember where I saved them. Fortunately, Linux includes a variety of different utilities that you can use to search for a specific file ordirectory in the file system, so in this lesson, we're going to review the find command, the locate command, the whereis command, and the which command. find Command 0:29-3:02 Let's begin by looking at the find command. The find utility is a very useful tool that you can use to search for files and folders within the Linux file system. The syntax is shown here. First, we enter find at the shell prompt, and then we have to specifywhere we want the find command to start looking for the file in question. In this example, I specified /home. Now here's the important thing you need to remember, by default the findcommand will look for the file in question in /home if we specify that here, but it will also look in all the subdirectories of /home and all the subdirectories of those subdirectories. It will search recursively through the directory tree starting at the directory we specify trying to find the file name in question, and then we use the -name parameter to specify what file we're actually looking for. In this case, we're looking for a file named files.txt. When I run the command, find will start in home and it'll look for any file that matches the search string that we specify, and as you can see here the output will report where it found that file at. In this case, it found the file in /home/rtracy and the file name as we specified is files.txt. Be aware that you can use regularexpressions with find to make your searching a little more flexible. For example, let's suppose you need to find all of the log files that have been stored on your system and we're going to assume that all the log files have an extension of .log. To do this, we would enter find, and then we'd specify where wewant to start searching. In this case, we want to find any fileanywhere in the file system that ends in .log, so we're going to specify the start search location as just / that's the top of the file system tree, and remember that by default, find searchesrecursively so it'll start looking in the root directory and then it'll start looking in every single subdirectory of the root directory, and then it'll start looking in every subdirectory of everysubdirectory of every subdirectory for the file name that we specify. Then we use the -name parameter to specify what file names we're looking for and then we specify *.log. Now star is an example of the regular expression. That means match anything so it doesn't matter what the file name is as long as it ends in .log, and then you can see here the find commandstarted reporting what it found. It found several different files that end in .log, and it outputs their location and file name on the screen.
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 23 pages?

  • Spring '19
  • Jacob Taylor

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes