Video:How to Use the Find Command in Linuxwith Zoya Popova
The find command is a great way to navigate through your hard drive with Linux. This video from About.com will explain how to use the find command in Linux.See Transcript
Transcript:How to Use the Find Command in Linux
Hi, I'm Zoya Popova for About.com, and today I'm going to show you how to use the find command in Linux.
Beginning With Find Command in Linux
The function of the find command is to locate files and directories within your file system. So go ahead and type "find", and next, you should specify the location you want to be searched. If you just type "find /", it will go looking through your root directory, which basically means all of your system. If you'd like to limit your search to a certain directory, you should specify the pathway to that directory. For example, by typing "find /home/zoya", I can do a search within my home directory.
Specify Criteria in Find Command
Next, you should specify the criteria of your search. For example, if you're searching by name, type "-name". And let's say I'm searching for a file named "Document1.odt". My command will look like this: find /home/zoya -name Document1.odt. Hit "Enter" to run the command, and in the output, we can see the pathway to the file we were looking for: /home/zoya/Downloads/Document1.odt. Document1.odt is located in the Downloads directory, which is in turn in my home directory.
Perform Case Insensitive Search in Linux
Now, one thing to remember is that Linux is case sensitive. If your command looked like this: find /home/zoya -name document1.odt, you would get zero output. You could solve this problem by using a slightly different search criterion. Let's bring up our previous command by hitting the up arrow, and in this command we're going to change "-name" to "-iname": find /home/zoya -iname document1.odt. This criterion will perform a case-insensitive search. So even though we used a lower-case "d" in our command, we are able to find our Document1.odt, starting with an upper-case "D": /home/zoya/Downloads/Document1.odt.
Use Wildcard in Linux Find Command
Now, another thing that may cause problems is that sometimes you don't remember the extension of the file you're looking for. So let's bring up our previous command: find /home/zoya -iname document1.odt. And let's say we're not sure what the extension of the file is: find /home/zoya -iname document1. In this case, you can use a wildcard. A wildcard is usually denoted by an asterisk (*), but in Linux, you should use \* for a wildcard: find /home/zoya -iname document1.\*. Run this command... And once again, we've managed to locate the file "Document1.odt": /home/zoya/Downloads/Document1.odt.
Search by File Size
There are a number of other criteria you can use with your find command. For example, if you want to search by size, you will use the "-size" criterion, followed by size parameters. For example, if you're searching for files over 50 megabytes, you will put down +50M: find /home/zoya/Downloads -size +50M. This time we're performing a search within my Downloads folder, and in the output, we can see that there's only one file in that folder that exceeds 50 megabytes: /home/zoya/Downloads/FreeStudio.exe.
There are many other search criteria that you can use, and you can learn about them by entering man find, which will take you to the manual of the find command. And this is it for us for today. Thank you for watching, and for more information, please visit us at About.com.