In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the case of linux quickly finding files, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!
When using linux, you often need to look up files. The main commands found are find and grep, and there is a difference between the two commands.
Difference:
(1) the find command is based on the attributes of the file, such as file name, file size, owner, group to which it belongs, whether it is empty, access time, modification time, etc.
(2) grep searches according to the contents of the file and matches each line of the file according to the given pattern (patter).
(3) which looks at the location of the executable file, which can only be used by programs with environment variables set.
(4) whereis searches for specific files, which can only be used to find binaries, source code files and man man pages.
(5) locate works with the database to view file locations. Details: locate-h to view help information
I. find command
Basic format: find path expression
1. Find by file name
(1) find /-name httpd.conf # looks for the file httpd.conf in the root directory, which means to search the entire hard disk.
(2) find / etc-name httpd.conf # files httpd.conf in / etc directory
(3) find / etc-name'* srm*' # uses the wildcard character * (0 or any number). Means to look for files with the string 'srm' in the file name in the / etc directory
(4) find. -name 'srm*' # means to find files in the current directory whose names begin with the string' srm'
two。 Search according to file characteristics
(1) find /-amin-10 # finds the files accessed in the last 10 minutes of the system (access time)
(2) find /-atime-2 # finds the files accessed in the last 48 hours in the system
(3) find /-empty # looks for files or folders that are empty in the system
(4) find /-group cat # finds files in the system that belong to cat with group
(5) find /-mmin-5 # finds files that have been modified in the last 5 minutes of the system (modify time)
(6) find /-mtime-1 # finds files that have been modified in the last 24 hours of the system
(7) find /-user fred # finds files that belong to the user fred in the system
(8) find /-size + 10000c # find files larger than 10000000 bytes (c: bytes, w: double words, KRO KB Magi MRO MBMGRO GB)
(9) find /-size-1000k # find files smaller than 1000KB
3. Use hybrid lookup to find files
The parameters are:! ,-and (- a),-or (- o).
(1) find / tmp-size + 10000c-and-mtime + 2 # look for files larger than 10000 bytes in the / tmp directory and modify them in the last 2 minutes
(2) find /-user fred-or-user george # look for files whose users are fred or george in the / directory
(3) find / tmp!-user panda # find all files that do not belong to panda users in the / tmp directory
II. Grep command
Basic format: find expression
1. Main parameters
[options] main parameters:
-c: outputs only the count of matching rows.
-I: case-insensitive
-h: the file name is not displayed when querying multiple files.
-l: when querying multiple files, only the file names that contain matching characters are output.
-n: displays matching lines and line numbers.
-s: does not display error messages that do not exist or have no matching text.
-v: displays all lines that do not contain matching text.
The main parameters of the pattern regular expression:
\: ignore the original meaning of special characters in regular expressions.
^: matches the start line of the regular expression.
$: matches the end line of the regular expression.
\: to the end of the line matching the regular expression.
[]: single character, such as [A], that is, A meets the requirements.
[-]: range, such as [Amurz], that is, A, B, C all the way up to Z meet the requirements.
.: all single characters.
*: there are characters, and the length can be 0.
two。 Case study
Grep-r "string" is very convenient
(1) grep 'test' d * # displays the lines containing test in all files starting with d
(2) grep 'test' aa bb cc # displays the line containing test in the aa,bb,cc file
(3) grep'[amurz]\ {5\}'aa # shows all lines that contain at least five consecutive lowercase characters per string
(4) grep magic / usr/src # shows that the files in the / usr/src directory (excluding subdirectories) contain lines of magic
(5) grep-r magic / usr/src # shows that the files (including subdirectories) in the / usr/src directory contain lines of magic
(6) grep-w pattern files: matches only the whole word, not part of the string (such as matching 'magic', instead of' magical')
The above is all the contents of the linux quick search file case, thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.