Home > Article > Operation and Maintenance > How to query directory in linux
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]".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Open the shell connection tool, connect to the server, use pwd to view the current directory, usually the default is under the home directory~:
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
If we want Find an nginx configuration file nginx.conf, then we can find it through the find command: find . -name 'nginx.conf'
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':
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:
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
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
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!