<\/p>\n
Linux find file command explained. Finding files using the command line on a Linux machine could be very uncomfortable experience, especially for the beginners. Without a GUI it is very difficult to navigate through the directories and find the files you need. In this tutorial, we will show you how to find a specific file in Linux, using the command line.<\/p>\n
<\/p>\n
The first thing your need to do is to connect to your Linux VPS via SSH<\/a>. There are two common ways to search for a file under Linux. The one way is to use the find<\/code> command and the other way is to use the
locate<\/code> command. Let’s start with the former.<\/p>\n
1. Linux Find File Command<\/h2>\nThe Linux find file command<\/strong> allows you to search the directory tree using various search criteria such as name, type, ownership, size etc. This is the basic syntax:<\/p>\n
# find path expression search-term<\/pre>\nHere is a brief example on how to use the Linux find command to find a specific file by its name:<\/p>\n
# find -name test.file<\/pre>\nThe command will search the entire directory tree for a file named
test.file<\/code> and will provide you with the location. You can try using a name of a file that actually exists on your Linux VPS.<\/p>\n
Sometimes it may take few minutes for the find command to search the entire directory tree, especially if there are many files and directories on your system. To save a significant amount of time you can specify the searching directory. For example, if you know that the
test.file<\/code> is somewhere in the
\/var<\/code> directory, there is no need to search other directories. Therefore, you can use the command below:<\/p>\n
# find \/var -name test.file<\/pre>\n
There is also an option to search for a file by time, size, ownership, permissions etc. For more information about these options, you can check the Linux find file command<\/strong> man page.<\/p>\n
# man find<\/pre>\n2. Locate File command<\/h2>\n
In order to be able to use the Linux
locate<\/code> command, you need to install it first.<\/p>\n
If you are using an
Ubuntu VPS<\/a>, run the following commands to install locate:<\/p>\n
# apt-get update\n# apt-get install mlocate<\/pre>\n
If you are using a CentOS VPS<\/a>, run the following command to install locate:<\/p>\n
# yum install mlocate<\/pre>\nLocate is a faster option to find a file since it searches for the files in a database. To update the search databases run the following command:<\/p>\n
# updatedb<\/pre>\nTo find files in Linux with locate, use the following syntax:<\/p>\n
# locate test.file<\/pre>\nJust like with the find command, there are many options to filter the search output. To learn more about this you can check the Linux locate command<\/strong> man page.<\/p>\n
# man locate<\/pre>\n
\nOf course, you don\u2019t have to use the Linux find file, if you use one of our Linux hosting services<\/a>, in which case you can simply ask our expert Linux admins to look and find the files on Linux for you. They are available 24\u00d77 and will take care of your request immediately. For more updates, you might want to consider reading Find Large Files in Linux<\/a>.<\/p>\n