![]() As you can see from below demonstration, output of locate -i -0 file.txt command is showing in one line. If you want to display the output of searches in one line then you need to use -0 option with -i option as shown below. ![]() Example 9: Display Output in One Line using locate command in Linux As shown in the below example, here we are trying to search all the matches with file keyword at the end( $). If you want to search any file using regular expressions then you can search it by using -r option with locate command in Linux as shown below. Example 8: Search File Using Regular Expressions S : Write statistics about each read database to standard output instead of searching for files and exit successfully. ~]# locate -Sĭatabase /var/lib/mlocate/mlocate.db: 5,253 directories Using this command you can check database path, number of directories, number of files, total size of files and total size of the database as shown below. If you want to know more about mlocate database then you can check it through locate -S command as shown below. Example 7: Show locate DB Stats using locate command in Linux i : Ignore case distinctions when matching patterns. ~]# locate -i File.txt /home/centos/file.txt It will ignore the Case sensitive F and search all the files matches with file.txt in the System. As shown in the below demonstration, we are trying to search a file File.txt using locate -i File.txt command. If you want to ignore the case sensitivity then you need to use -i option with locate command in Linux. n : Exit successfully after finding LIMIT entries. ~]# locate *.txt -n 3 /home/centos/file.txt If you want to limit the number of search output during from locate run then you can do it by using -n option and passing the number of total search as an argument to locate command as shown below. ~]# locate -c *.txt 4 Example 5: Limit the Number of Search Output txt then you need to use below locate command in Linux. If instead of giving complete file name if you use wild card character( *) to count the occurrence of all the files ending with. Example 4: Display total number of Specific Matching Pattern Files c : Instead of writing file names on standard output, write the number of matching entries only. In below demonstration we are counting the total number of file.txt using locate -c file.txt command. If you want to count the total number of occurrence of a file then you need to use below locate command in Linux. root/file.txt Example 3: Display total number of Matching Files V : Write information about the version and license of locate on standard output and exit successfully.Īdvertisements ~]# locate file.txt /home/centos/file.txt This program is provided with NO WARRANTY, to the extent permitted by law. This software is distributed under the GPL v.2. As you can check from the output current locate command version is 0.26 ~]# locate -V mlocate 0.26Ĭopyright (C) 2007 Red Hat, Inc. If you want to check the locate command version then you need to run locate -V command as shown below. Hence locate command is much faster than find command.Īlso Read: How to Install locate command in Linux (RedHat/CentOS 7/8) Using 5 Easy Steps Example 1. There is a background daemon process which runs and populates the locate database so that it will query and get the location of files in almost no time whereas find command has to physically search in every location to find any files which makes it a slow process. Locate command maintains a Database to do all its queries whereas find command does not have this feature. Difference between locate and Find command It is traditionally faster in comparison to other searching tools like find command in Linux due to its separate maintenance of a database to keep the records of all file paths and location. locate is a very useful command in Linux to search a file in almost no time. In this article, I will take you through 15 Best Examples of locate command in Linux (RedHat/CentOS 7/8).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |