In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
There are several file lookup instructions under Linux: find, whereis, which, and locate.
● which: view the location of the executable file
● whereis: where to view files
● locate: view files with database
● find: actual search for hard disk queries
Find is the most commonly used and powerful lookup command. It can do real-time search, accurate search, but the speed is slow. The following is mainly about the usage of find instruction in detail.
●●● find directive:
[format] find [specify lookup directory] [lookup rules] [action to be executed after lookup]
The default path is the current directory; by default, the action executed after the search is-print.
-print / / Action by default
-ls / / display it with ls after finding it
-ok [commend] / / ask the user whether or not to execute the command after lookup
-exec [commend] / / execute the command without asking the user after searching
Here we should pay attention to the use of {}: replace the found file
1. Specify the lookup directory
2. Find according to the file name
-name: search by file name (exact search)
-iname: looks up by file name, but is not case-sensitive
In addition, the knowledge of file name wildcard is introduced.
1) * means to match any character
2)? Represents a wildcard with any single character
3) [] indicates any character in wildcard parentheses
3. Regular expression lookup
! Non-conditional
-a: and condition (- and)
-o: or condition (- or), which connects two different conditions (one of which is satisfied)
-not non-conditional (vs. "!" Same, reverse the condition)
4. Find the file according to the file type
[- type]
F: normal file; d: directory file; l: link file; b: block device file; c: character device file; p: pipe file; s: socket file
5. Find files according to file size
[- size]
-size n: find files whose file length is equal to n;-size-n: find files whose file length is less than n;-size + n: find files whose file length is greater than n
6. Find the file according to the file time
-atime: access time, the last time the user accessed the file
-mtime: the modification time, the last time the file content was modified.
-ctime: the time when the file metadata (metadata, such as permissions or ownership) was last changed.
7. Find files according to file permissions
[- prem]
Permission symbol: rex stands for readable, writable, and executable, respectively. When the permission symbol is-eMui: it can only be written, and the octal value is expressed as 2, which is expressed in turn.
8. Find the file according to the user and group to which the file belongs
-user: find files according to the owner
-group: find files according to the group
-nouser and-nogroup: look for files that have neither owners nor groups throughout the system (such files are usually dangerous, and as system engineers we should get rid of them in time)
9. Find users according to uid and gid
Gid is GroupId, or group ID, which is a unique identifier used to identify a user group
Uid is UserId, or user ID, which is a unique identifier used to identify each user
User group: set the same type of users to the same group, for example, all system administrators can be set to admin group, it is easy to assign permissions, and some important files can be set so that all admin group users can read and write, so that permissions can be assigned.
Each user has a unique user id, and each user group has a unique group id
●● which directive:
The which command searches for the location of a system command in the path specified by the PATH variable and returns the first search result. That is, using the which command, you can see whether a system command exists and where the command is being executed.
[format] which executable file name
-n: specifies the length of the file name, which must be greater than or equal to the longest file name of all files.
-p: same as the-n parameter, but here includes the path to the file.
-w: specifies the width of the field on output.
-V: displays version information
Which searches for runnable files according to the directories in the PATH variables configured by the user, so different PATH configurations find different commands. Cd is a built-in command for bash, but which defaults to finding the directory specified in PATH, so you can't find it. When looking for which, there will be two which, one of which is alias, which is the so-called command alias, meaning that typing which equates to the following string of commands.
● whereis directive:
The whereis command can only be used to search for program names. Only binary files (parameter-b), man description files (parameter-m), and source code files (parameter-s) are searched. If the parameter is omitted, all information is returned.
The whereis command locates the location of executable files, source code files, and help files in the file system. The properties of these files should belong to the original code, binaries, or help files. Whereis programs also have the ability to search source code, specify alternate search paths, and search for unusual items.
[format] whereis file name
-b: locate the executable file.
-m: locate the help file.
-s: locate the source code file.
-u: search the default path for files other than executable files, source code files, and help files.
Compared with find, whereis lookup is very fast, because the linux system records all the files in the system in a database file, and when using whereis and locate, it looks for data from the database, rather than traversing the hard disk as the find command does, which is efficient.
However, the database file is not updated in real time and is updated once a week by default, so when looking for files with whereis and locate, sometimes you will find the data that has been deleted, or the file has just been created but cannot be found, because the database file has not been updated.
● locate directive:
Locate function: users can quickly search for specified files in the file system. The method is to first set up an index database that includes all the file names and paths in the system, and then when looking for it, you only need to query the index database without actually going deep into the file system.
[format] locate file name
Eg:locate passwd (anything that contains passwd will be displayed)
Locate can be filtered
-I: case-insensitive when looking for files
-n: only the first N lines of the search results are displayed
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.