In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "file and content search command arrangement in the ubuntu system". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the file and content search command arrangement in the ubuntu system".
one。 Find by file name:
1. Find command
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).
The general form of the find command is
Find pathname-options [- print-exec-ok.]
Such as
Find /-name "filename"
Purpose: start searching for files called filename in the root directory "/". The file name "filename" can contain wildcards (*,? Note: filename is a file name string with or without the find command. It has many options that allow you to search for files in different ways, such as date, file size, permissions, owner, etc.
Parameters of the find command
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 to the user to determine whether to execute it.
3. Find command options
-name
Find the file by file name.
-perm
Find files according to file permissions.
-prune
Use this option to prevent the find command from looking in the currently specified directory, and if you use the-depth option at the same time, the-prune will be ignored by the find command.
-user
Find the file according to the owner of the file.
-group
Find the file by the group to which the file belongs.
-mtime-n + n
Find the file according to the change time of the file,-n means that the file change time is within n days from now, and + n means that the file change time was n days ago. The find command also has the-atime and-ctime options, but they all have the-m time option.
-nogroup
Look for 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
Find a file that does not have a valid owner, that is, the owner of the file does not exist in / etc/passwd.
-newer file1! File2
Find files whose change time is newer than the file file1 but older than the file file2.
-type
Find 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.
2. Locate command
Locate filename
The locate command is actually another way to write "find-name", but much faster than the latter, because instead of searching for a specific directory, it searches for a database (/ var/lib/locatedb) that contains all the local file information. The Linux system automatically creates this database and automatically updates it once a day, so you can't find the most recently changed files using the locate command. To avoid this, you can manually update the database using the updatedb command before using locate.
Examples of use of the locate command:
$locate / etc/sh
Search for all files that start with sh in the etc directory.
$locate ~ / m
Search for all files that start with m in the user's home directory.
$locate-I ~ / m
Search for all files that start with m in the user's home directory, ignoring case.
A file name containing the string "filename" was found. This is easier than the find command. But based on the database (usually rebuilt at night), you can't find the file you just saved to the file system. To force an immediate update of the database, you can use as a superuser: updatedb& (with no spaces in the middle)
3. Which command
Which executeable_name
Find the executable file, according to the file name of the executable file.
For example, which apache2, return / usr/sbin/apache2
two。 Find by the contents of the file
1. Grep-n string name / filepath/filename
Returns the line containing the string, which can be multiple lines. And contains the number of rows.
2. Sudo gedit / filepath/filename
Then, use ctrl+F to find the corresponding string.
3. Vi or less command can find the corresponding content.
For example, vi / filepath/filename, then enter "/ string" and press the letter "n" to the next matching string
4. Tail command
A special way to view the contents of a file
1. If you only want to see the first five lines of the file, you can use the head command, such as:
Head-5 / etc/passwd
two。 If you want to view the last 10 lines of the file, use the tail command, such as:
Tail-20 / etc/passwd
Tail-f / var/log/messages
The parameter-f causes tail to keep reading the latest content, which has the effect of real-time monitoring.
Tail-f / var/log/messages
After pressing Ctrl+C, exit directly from the script to the prompt
Thank you for your reading, the above is the content of "file and content search command arrangement in ubuntu system". After the study of this article, I believe you have a deeper understanding of the problem of file and content search command arrangement in ubuntu system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.