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)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to back up vscode settings and extensions How to back up vscode settings and extensions Apr 15, 2025 pm 05:18 PM

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.

See all articles