In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "detailed introduction of Linux search command and find command". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Locate command for file search
Locate:
Non-real-time, fuzzy search based on the system-wide file database
Update manually generates the file database
High speed
Dependent on updatedb database
# manually update locate database
[root@lovelace scripts] # updatedb
# use locate to find files (fast to say)
[root@lovelace scripts] # locate * .py
/ home/scripts/factorial.py
/ home/scripts/input.py
/ usr/lib/python2.4/fileinput.py
/ usr/lib/python2.4/fileinput.pyc
/ usr/lib/python2.4/fileinput.pyo
/ usr/lib/python2.4/site-packages/dogtail/rawinput.py
/ usr/lib/python2.4/site-packages/dogtail/rawinput.pyc
/ usr/lib/python2.4/site-packages/dogtail/rawinput.pyo
/ usr/lib/python2.4/test/pyclbr_input.py
/ usr/lib/python2.4/test/pyclbr_input.pyc
/ usr/lib/python2.4/test/pyclbr_input.pyo
/ usr/lib/python2.4/test/test_fileinput.py
/ usr/lib/python2.4/test/test_fileinput.pyc
/ usr/lib/python2.4/test/test_fileinput.pyo
II. Find command for file search
Find:
Real time
Precision
Support for many lookup rules
Traversing all the files in the specified directory to complete the search, slow
Find search path search criteria find the future processing operation
Find path: default to current directory
Find criteria: default to all files under the specified path
Find future processing operations: default to display
Matching criteria:
-name' filename': makes exact matching of file names
File name wildcard:
* any character of any length
? Any single character
Characters in [] option
-case insensitive when matching iname 'filename': file names
-regex pattern matches file names based on regular expressions
-user username: search according to the owner
-group groupname: search by group
-gid gid: search based on gid
-uid uid:: searches according to udi
-nouser looks for files without owners
-nogroup has no files belonging to the group
Example: find / tmp-nouser
[root@lovelace scripts] # find / tmp-name test
/ tmp/sources/httpd-2.2.17/srclib/apr-util/test
/ tmp/sources/httpd-2.2.17/srclib/apr/test
/ tmp/sources/httpd-2.2.17/modules/test
/ tmp/sources/httpd-2.2.17/test
/ tmp/test
Find it according to the file type
-type
F: ordinary files
D: directory
C: character
B: block equipment
L: link
P: pipe
S: socket
Example:find / etc-type d
# find the / tmp directory with the name test and the file format as a directory
[root@lovelace scripts] # find / tmp-type d-a-name test
/ tmp/sources/httpd-2.2.17/srclib/apr-util/test
/ tmp/sources/httpd-2.2.17/srclib/apr/test
/ tmp/sources/httpd-2.2.17/modules/test
/ tmp/sources/httpd-2.2.17/test
/ tmp/test
Find based on file size
-size
[+ | -] # k without + and-means an exact match
[+ | -] # m
[+ | -] # G
Example:find / tmp-size + 10m find files larger than 10m in / etc directory
Combination condition: this requires an understanding of Morgan's law
-a: compared to default
-o: or
-not: not
Example:find / tmp-not-user user1-o-not-type d
# find directories with file formats between 26k and 32k under the / tmp directory
[root@lovelace scripts] # find / tmp-type d-a-size + 16k-a-size-32k
/ tmp/sources/httpd-2.2.17/docs/manual/mod
/ tmp/sources/php-5.2.13/ext/reflection/tests
/ tmp/sources/php-5.2.13/ext/date/tests
/ tmp/sources/php-5.2.13/ext/spl/tests
/ tmp/sources/php-5.2.13/tests/classes
/ tmp/sources/php-5.2.13/Zend/tests
Look up according to the file timestamp:
Measured in days:
Change time:-mtime
Modification time:-ctime
View time:-atime
[+ | -] # default timestamp is 5 days
-visited within 5:5 days
+ 5: I haven't visited for at least 5 days.
5: visited exactly 5 days from now
Measured in minutes:
-mmin:
-cmin:
-amin:
Find / tmp-amin-Files accessed within 5 5 minutes
If at least how long the file has not been accessed, and how much the file size exceeds, the delete operation will be performed.
Find / tmp-atime + 30-a-size + 100m-exec'rm-rf *'\
# find files in the home directory that have not been accessed for at least 5 days
[root@lovelace scripts] # find / home/-ctime-5
/ home/scripts
/ home/scripts/list
/ home/scripts/for
/ home/scripts/for/dir.sh
/ home/scripts/for/three.sh
/ home/scripts/for/checkbash.sh
/ home/scripts/for/sorsum.sh
/ home/scripts/while
/ home/scripts/while/readpasswd.sh
/ home/scripts/while/catwhile.sh
/ home/scripts/case
/ home/scripts/case/showmenu.sh
/ home/scripts/case/showmenu
/ home/scripts/case/2showmenu.sh
/ home/scripts/if
/ home/scripts/if/grade.sh
/ home/scripts/51cto
/ home/scripts/51cto/info.tt
/ home/scripts/51cto/info.sh
/ home/scripts/51cto/1.sh
/ home/scripts/51cto/argument.sh
/ home/scripts/51cto/sum.sh
Find based on permissions:
-perm mode: exact match
-perm-mode: each permission must exactly match the file permissions that fully contain this mode.
-perm / mode: any one of the 9-bit permissions that meets the criteria
Example:find / tmp-perm-001Lookup files with write permission from other users
Actions of find:
-print default
-ls: displays every information in the file in a form similar to ls-l
-ok command {}\; will perform the query operation every time, which requires user confirmation.
-exec command {}\; will not wake up to inquire about the operation
Quote the original forehead name and use {}
Example:find / tmp-perm-020-exec mv {}. New\
# find files with sizes between 16k and 32k in home, then pass them to exec and display them
[root@lovelace scripts] # find / home/-size + 16k-a-size-32k-exec ls-lh {}\
-rw-r--r-- 1 root root 20K 05-03 03:04 / home/nick/etc/gconf/gconf.xml.defaults/%gconf-tree-li.xml
-rw-r--r-- 1 root root 20K 05-03 03:04 / home/nick/etc/gconf/gconf.xml.defaults/%gconf-tree-ug.xml
-rw-r--r-- 1 root root 25K 05-03 03:04 / home/nick/etc/gconf/schemas/drivemount.schemas
-rw-r--r-- 1 root root 20K 05-03 03:04 / home/nick/etc/gconf/schemas/gnome-volume-control.schemas
-rw-r--r-- 1 root root 21K 05-03 03:04 / home/nick/etc/gconf/schemas/system_smb.schemas
-rw-r--r-- 1 root root 22K 05-03 03:04 / home/nick/etc/gconf/schemas/desktop_gnome_thumbnailers.schemas
-rw-r--r-- 1 root root 17K 05-03 03:04 / home/nick/etc/gconf/schemas/apps_gnome_settings_daemon_default_editor.schemas
Find and xargs commands
Xargs: the function is to convert the parameter list into small pieces and pass it to other commands to avoid the problem that the parameter list is too long.
This command is more powerful than-exec command. When used with find, it is usually passed to xargs through pipeline
Find / tmp-size + 100m | xargs'rm-rf'
III. Other search commands
Which: locate the full path of a command, which may show the alias of the command
# use the which command to find the full path of the ls command
[root@lovelace scripts] # which ls
Alias ls='ls-color=tty'
/ bin/ls
# use the ldd command to view the library files that ls depends on (the full path of ls is required here)
[root@lovelace scripts] # ldd / bin/ls
Linux-gate.so.1 = > (0x00cf8000)
Librt.so.1 = > / lib/librt.so.1 (0x00d8d000)
Libacl.so.1 = > / lib/libacl.so.1 (0x00d62000)
Libselinux.so.1 = > / lib/libselinux.so.1 (0x00de0000)
Libc.so.6 = > / lib/libc.so.6 (0x00110000)
Libpthread.so.0 = > / lib/libpthread.so.0 (0x00d71000)
/ lib/ld-linux.so.2 (0x00baf000)
Libattr.so.1 = > / lib/libattr.so.1 (0x003a9000)
Libdl.so.2 = > / lib/libdl.so.2 (0x00d55000)
Libsepol.so.1 = > / lib/libsepol.so.1 (0x00d98000)
Whereis: similar to which, but additionally gives the full path of the man page that gives the command
# use whereis to view the full path of the command and the corresponding man file
[root@lovelace scripts] # whereis ls
Ls: / bin/ls / usr/share/man/man1/ls.1.gz / usr/share/man/man1p/ls.1p.gz
# man View the corresponding file
[root@lovelace scripts] # man 1 ls
# man View the corresponding file
[root@lovelace scripts] #
[root@lovelace scripts] # man 1p ls
Whatis: file will be queried in the whatis database. When you want to confirm system commands and important configuration files, this command is very important and can be used as a simple man command.
[root@lovelace scripts] # whatis ls
Ls (1)-list directory contents
Ls (1p)-list directory contents
Summary: before facing which, whatis, whereis, I was always confused, and the role of these commands was always confused, so I would like to make a note to prevent confusion. In addition, the find command is very important to our operation and maintenance work, especially for whether the file has been tampered with after the server has been compromised.
This is the end of the detailed introduction of the Linux search command and the find command. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.