In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
We often look for a file in linux, but we don't know where we put it. We can search it with the following commands:
Which looks at the location of the executable file.
Whereis views the location of the file.
Locate works with the database to view the file location.
Find actually searches the hard disk to query the file name
Which
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.
1. Command format: which executable file name
2. Command function: the which command searches the location of a system command in the path specified by the PATH variable and returns the first search result.
Example 1:
Displays information about aliases when looking for commands with aliases
For example: search for the location of the ls command in the path specified by the environment variable
3. Command parameters:
-n specifies the length of the file name, which must be greater than or equal to the longest file name of all files.
The-p parameter is the same as the-n parameter, but here the path to the file is included.
-w specifies the width of the field on output.
-V displays version information
Which-v
Whereis directive:
The whereis command can only be used to search for program names, and 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.
Compared with find, whereis lookup is very fast, because the linux system will record all the files in the system in a database file, when using whereis and the locate to be introduced below, it will look for data from the database, rather than traversing the hard disk as the find command does, it will naturally be very efficient.
However, the database file is not updated in real time, and by default it is updated once a week, so when we look for files with whereis and locate, we sometimes find the data that has been deleted, or just created the file, but can not find it, because the database file has not been updated.
1. Command format:
Whereis [- bmsu] [BMS directory name-f] file name
2. Command function:
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, binary text, or help files. Whereis programs also have the ability to search source code, specify alternate search paths, and search for unusual items.
3. Command parameters:
-b locate the executable file.
-m locate the help file.
-s locate the source code file.
-u search for files under the default path other than executable files, source code files, and help files.
-B specifies the path to search for executable files.
-M specifies the path to search for help files.
-S specifies the path to search for source code files.
4. Use an example:
Whereis-b grep locates the executable file.
Whereis-m grep locates the help file.
Whereis-s grep locates the source code file.
Whereis-u grep searches for files other than executable files, source code files, and help files in the default path
-B specifies the path to search for executable files.
-M specifies the path to search for help files.
-S specifies the path to search for source code files.
Find directive:
The find command under Linux searches for files in the directory structure and performs the specified operation. The find command under Linux provides quite a number of search conditions and is very powerful. Because of the powerful features of find, there are many options, most of which are worth taking the time to learn about. Even if the system contains a network file system (NFS), the find command is also valid in that file system, only you have the appropriate permissions. When running a resource-consuming find command, many people tend to leave it in the background because it can take a long time to traverse a large file system (in this case, a file system of more than 30 gigabytes).
1. Command format:
Find pathname-options [- print-exec-ok.]
2. Command function:
Used to find files in the file tree and process them accordingly (may access the disk)
3. Command parameters:
Pathname: the directory path that the find command looks for. For example, with. To represent the current directory and / to represent the system root directory
The-print: find command outputs matching files to standard output.
The-exec: find command executes the shell command given by this parameter on the matching file. The corresponding command is in the form 'command' {}\;, notice the space between {} and\;.
-ok: the function is the same as-exec, except that the shell command given by this parameter is executed in a more secure mode, and before each command is executed, a prompt is given for the user to determine whether to execute it.
Use case:
Find the test.cpp in the current directory and output
Find the test.c in the current directory and display permissions
Find the test.c in the current directory and display permissions
4. Command options:
-name looks for files by file name (precise lookup is case-sensitive)
-iname looks for files by file name (case-insensitive)
-perm finds files according to file permissions
-user looks for files by file category.
-group looks for files according to the group to which they belong
-mtime-n + n look up the file according to the change time of the file
-n means that the file has been changed within n days from now.
+ n means the file was changed n days ago.
The find command also has-atime and-ctime options, but they are all the same as the-m time option
-nogroup finds a file that does not have a valid group, that is, the group to which the file belongs does not exist in / etc/groups
-nouser looks for a file without a valid owner, that is, the owner of the file does not exist in / etc/ passwd.
-newer file1! File2 finds files whose change time is newer than the file file1 but older than the file file2
-type looks for a certain type of file, such as
B-block device file
D-directory
C-character device file
P-pipe file
L-symbolic link file
F-ordinary file
-size n: [C] looks for files with n blocks of file length, with c indicating that the file length is in bytes.
-depth: when looking for files, first look for the files in the current directory, and then look in their subdirectories
-fstype: look for files located in a certain type of file system, which can usually be found in the configuration file / etc/fstab, which contains information about the file system in this system.
-mount: does not cross the file system mount point when looking for files.
-follow: if the find command encounters a symbolic link file, it tracks to the file that the link points to
-cpio: use the cpio command on matching files to back up the files to the tape device.
In addition, the differences between the following three:
-build time to find files,-n refers to within n days, + n refers to n days ago
Example:
1. Find files in the current directory that were changed before 5 days and delete them:
Find. -type f-mtime + 5-ok rm {}\
2. Linux's method of finding files with file size of XX with find command
For example, a file of 5556 bytes can be written like this
That is, find files that are more than 5555 bytes and less than 5557 bytes. The above search is the / root directory.
Find / root-size-5557c-size + 5555c-exec ls-ld {}\
Find files that are less than 500K and greater than 50K
Find / root-size-500K-size + 50K-exec ls-ld {}\
Exercise:
Find the directory under the / directory with the file name test
$find /-name test-print
Find all current directories and sort
Ascending order
Descending order
Find directories in all directory names that end with ".log"
] $find /-name'* .log'- print
Find the directory accessed in the last 5 minutes in the system
Find the files accessed in the system in the last 5 days
Find /-mtime-5
Find all files in the current directory with permissions of 775 and set them to 777
Find. -perm 775-ok chmod 777 {}\
Find a file with a file size of 10k and delete it
Locate directive:
Permissions: all users
Usage: locate [- Q] [- d] [--database=]
Locate [- r] [--regexp=]
Locate [- qv] [- o] [--output=]
Locate [- e] [- f]
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.