Home  >  Article  >  Operation and Maintenance  >  How to query directory in linux

How to query directory in linux

WBOY
WBOYOriginal
2022-01-27 11:55:0132689browse

Method: 1. Use the pwd command to view the current directory, the syntax is "pwd [--help][--version]"; 2. Use the find command to query the specified directory, the syntax is "find path -option [-print] [-exec -ok command]".

How to query directory in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to query the directory in Linux

Open the shell connection tool, connect to the server, use pwd to view the current directory, usually the default is under the home directory~:

How to query directory in linux

Switch to the home directory through the command: cd /, then pwd to view the current directory, and use ls to view the files and directories in the current directory

How to query directory in linux

If we want Find an nginx configuration file nginx.conf, then we can find it through the find command: find . -name 'nginx.conf'

How to query directory in linux

In the above command, . indicates the current directory, If we want to specify a directory to search without switching directories, we can search through: find directory-name 'nginx.conf':

How to query directory in linux

If we don’t know the file The specific name just vaguely remembers a few key words, then we can search through fuzzy matching: find directory-name '*nginx*' Find:

How to query directory in linux

If we say The remembered file names are very limited, and there are too many files found, but if we remember the contents of some files, we can filter the file contents through the pipeline command: find directory-name '*nginx*' | xargs grep 'content', The following can be used to find all files with .conf results and content containing location

How to query directory in linux

If we don’t remember anything, but just vaguely remember the creation time of the file, then we still have You can search by file creation time

How to query directory in linux

find command is a powerful search command. The above only introduces the search by file name, file content and file modification time. And we can also use file permissions, file size, file owner and other information to find

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to query directory in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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