How to find file location in linux

Jun 16, 2021 pm 02:05 PM
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.

How to find file location in linux

#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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

See all articles