Home>Article>Operation and Maintenance> How to find file location in linux
In Linux, you can use the find or locate command to find the file location. The syntax format is "find / -name file name" and "locate file name". The find command is used to find files in a specified directory, and the locate command is used to find documents that meet the conditions.
#The operating environment of this tutorial: centos7 system, thinkpad t480 computer.
Because you want to install pl/sql, you need to look for the tnsnames.ora file. . Let’s see how to check which directory this file is in under Linux
find / -name tnsnames.ora
Find:
/opt/app/oracle/product/10.2 /network/admin/tnsnames.ora
/opt/app/oracle/product/10.2/network/admin/samples/tnsnames.ora
You can also use locate to find
locate tnsnames.ora
The result is: /opt/app/oracle/product/10.2/hs/admin/tnsnames.ora.sample
/opt/app/oracle/product/ 10.2/network/admin/tnsnames.ora
/opt/app/oracle/product/10.2/network/admin/samples/tnsnames.ora
1. Search by file name:
For example, if you forget which directory the httpd.conf file is in the system, or even don’t know where it is somewhere in the system, you can use the following command:
find / -name httpd.conf
This command syntax seems easy to understand. Just write -name directly after find, indicating that the system is required to search according to the file name, and finally write the target file httpd.conf Just name. After a while, the system will display a list of search results on the computer screen:
etc/httpd/conf/httpd.conf
This is the complete file httpd.conf in the Linux system path. The search was successful.
If the system does not display the results after entering the above search command, then do not think that the system has not executed the find / -name httpd.conf command, but it may be that the Apache server is not installed in your system. At this time, as long as you Install the Apache Web server, and then use find / -name httpd.conf to find this configuration file.
2. Error-free search techniques:
In the Linux system, the "find" command is a command that can be used by most system users and is not exclusive to ROOT system administrators. However, ordinary users may also encounter such a problem when using the "find" command, that is, the system administrator ROOT in the Linux system can set certain file directories to prohibited access mode. In this way, ordinary users do not have permission to use the "find" command to query these directories or files. When ordinary users use the "find" command to query these file directories, the words "Permissiondenied." (access prohibited) often appear. The system will not be able to query the file you want. In order to avoid such errors, we use the method of transferring error prompts to try to find files, for example, enter:
Find / -name access_log 2>/dev/null
3. According to some files Name search method:
For example, if we know that a file contains the three letters srm, then it is possible to find all the files in the system that contain these three letters. Enter:
Find /etc -name '*srm*'
This command indicates that the Linux system will search for all files containing the three letters srm in the entire /etc directory, such as absrmyz, tibc.srm, etc. All files that meet the conditions will be displayed. If you also know that this file starts with the three letters srm, then we can also omit the first asterisk, the command is as follows:
Find/etc -name 'srm*'
Only files like srmyz are found. Files like absrmyz or absrm do not meet the requirements and are not displayed. In this way, the efficiency and reliability of finding files are greatly enhanced.
4. Query method based on file characteristics:
If you only know the size, modification date and other characteristics of a certain file, you can also use the "find" command to find it out. This is the same as in the WINDOWS system. The "Search" function is basically the same. In Microsoft Search, Search Assistant makes it easier to search for files and folders, printers, users, and other computers on your network. It even makes searching on the Internet easier. Search Assistant also includes an indexing service that maintains an index of all the files on your computer, making searches faster. When using the Search Assistant, users can specify multiple search criteria. For example, users can search files and folders by name, type, and size. Users can even search for files containing specific text. If you are using Active Directory, you can also search for printers with a specific name or location.
For example, we know that the size of a Linux file is 1,500 bytes, then we can use the following command to query find /-size
1500c, the character c indicates that the size of the file to be searched is in bytes. If we don't even know the specific size of this file, we can also use fuzzy search in Linux to solve the problem. For example, if we enter the command find /-size 10000000c, it means that we specify that the system will find files larger than 10000000 bytes in the root directory and display them. The "+" in the command indicates that the system is required to list only files larger than the specified size, while using "-" indicates that the system is required to list files smaller than the specified size. The following list is the search action that the system will perform after using different "find" commands in Linux. From it, we can easily see that there are many ways to use the "find" command in Linux. As long as the "find" command is used flexibly to find files, It is no worse than the search ability in WINDOWS.
Find / -amin -10 # Find files accessed in the last 10 minutes in the system
Find / -atime -2 # Find files accessed in the last 48 hours in the system
Find / -empty # Find empty files or folders in the system
find / -group cat # Find files belonging to groupcat in the system
find / -mmin -5 #Find files modified in the last 5 minutes in the system
Find / -mtime -1 #Find files modified in the last 24 hours in the system
Find / -nouser #Find Files belonging to invalid users in the system
Find / -user fred #Find files belonging to the user FRED in the system
The following list is a list of the characteristics of the files that can be specified by the find command. Some conditions to search for. Not all search conditions are listed here. You can know the search functions of all find commands by referring to relevant books on Linux.
-amin n
Find the files accessed in the system in the last N minutes
-atime n
Find the files accessed in the system in the last n*24 hours
-cmin n
Find the files whose status was changed in the last N minutes in the system
-ctime n
Find the files whose status was changed in the last n*24 hours in the system Files that change status
-empty
Find blank files in the system, or blank file directories, or folders without subdirectories in the directory
-false
Find files that are always wrong in the system
-fstype type
Find files that exist in the specified file system in the system, for example: ext2.
n
Find the files in the system whose file number group ID is n
-group gname
Find the files in the system that belong to the gnam file group and specify the group and ID
(Recommended learning:linux tutorial)
The above is the detailed content of How to find file location in linux. For more information, please follow other related articles on the PHP Chinese website!