In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
File lookup
File lookup: locate, find
non-real-time lookup (database lookup): locate
real-time search: find
Locate
Common option
-I case-insensitive search
-n N enumerates only the first N matching items
-r uses basic regular expressions
Example
Trigger the establishment of a file index database
Find a file
Locate-I-n: find the first three lines of the passwd file
Locate-r: search for files ending in passed
Find
Real-time search tool to complete file search by traversing the specified path
Find [OPTION]... [search path] [search condition] [processing action]
lookup path: specify a specific destination path; default is the current directory
search criteria: specified search criteria, such as file name, size, type, permissions, etc. Default is to find all files under the specified path.
processing action: operate on files that meet the criteria, and output to the screen by default
Search condition 1. Look up by file name and inode:
-name "file name": supports using glob
*,?, [], [^]-iname "File name": is not case-sensitive
-inum n search by inode number
-samefile name files with the same inode number
-links n files with n links
-regex "PATTERN": matches the entire file path with PATTERN, not the file name
Example
The first level directory under root
Between the first and second levels
Find-depth: displays the file first, and then the parent directory
Find-name: find by file name
Find-iname: look up based on file name, case-insensitive
Find-inum n: find by inode node number
Find-samefile name: files with the same node node number
Find-links n: the condition that the number of links is n
Find-regex: matches the entire file path
two。 Look up according to the owner and group:
-user USERNAME: find files whose owner is the specified user (UID)
-group GRPNAME: find files that belong to the specified group (GID)
-uid UserID: find the file whose owner is the specified UID number
-gid GroupID: find files with the specified GID number in the group
-nouser: find files without owners
-nogroup: find files that do not belong to a group
Example
Find-user: find the owner wang
Find-nouser: find files without owners
3. According to the file type
-type TYPE
F: ordinary files
D: catalog file
L: symbolic link file
S: socket file
B: block device file
C: character device file
P: pipe file
Empty file or directory
-empty
example: find / app-type d-empty
Example
Find-type d: list only the directories under home
Find-empty: find the list of empty directories under home
4. According to the combination condition
Combination conditions:
And:-a
Or:-o
Non:-not!
De Morgan's law:
(not A) or (not B) = not (An and B)
(not A) and (not B) = not (An or B)
Example:
! a-a! B =! (a-o B)
! a-o! B =! (A-a B)
Example
Find-name snow.png
Find-iname snow.png
Find /-name "* .txt"
Find / var-name "log"
Find-user joe-group joe
Find-user joe-not-group joe
Find-user joe-o-user jane
Find-not (- user joe-o-user jane)
Find /-user joe-o-uid 500
Find the files in the / tmp directory where the owner is not root and the file name does not start with f
find / tmp (- not-user root-a-not-name'f')-ls
find / tmp-not (- user root-o-name'f')-ls
Exclude directory
Example:
Look for all files with the .conf suffix under / etc/ except the / etc/sane.d directory
find / etc-path'/ etc/sane.d'-a-prune-o-name "* .conf"
Find all files with the .conf suffix under / etc/ except / etc/sane.d and / etc/fonts
find / etc (- path "/ etc/sane.d"-o-path "/ etc/fonts")-a-prune-o name "* .conf"
Find-a: find an empty directory list under home and the name contains mage characters
Find-o: find an empty list of directories under home or names that contain mage characters
Find-not /!: find the list of non-directories under home
5. Based on file size
-size [+ | -] # UNIT
Common units of : K, M, Gregory c (byte)
# UNIT: #-1, #]
such as: 6k means (5kBI 6k)
-# UNIT: [0memorie muri 1]
such as:-6k means [0pje 5k]
+ # UNIT: (# ∞)
for example: + 6k means (6k, ∞)
Example: find-size:
6. According to the timestamp
In terms of "days"
-atime [+ | -] #
#: [#, # + 1)
+ #: [# + 1, ∞]
-#: [0Jing #)
-mtime
-ctime
In "minutes"
-amin
-mmin
-cmin
Example: find the files that appear within one minute
7. Find based on permissions
-perm [/ | -] MODE
MODE: exact permission matching
/ MODE: as long as one of the permissions of any kind of object can be matched, or relationship, + be eliminated from centos7
-MODE: each type of object must also have the specified permissions, and the relationship
0 indicates no concern.
Find-perm 755 will match files whose permission mode happens to be 755
Find-perm + 222will match as long as anyone has write permission
Find-perm-222will match only if everyone has write permission.
Find-perm-002will match only if someone else (other) has write permission.
Example
Find files with permissions of 600
As long as one of the main subordinate groups has r permission
All subordinate groups must have r permission.
Processing action
Example
-ls: execute the ls-l command on the found file
-delete: delete if you find it
-fls: all files under data found are saved to the specified file.
-ok: the user is asked to confirm when executing the command
-exec: execute the command directly without confirming the user
Parameter replacement because many commands do not support pipes | to pass parameters, xargs is used to generate parameters for a command, xargs can read data from stdin and separate stdin data into parameters with spaces or carriage returns. Many commands cannot accept too many parameters, and command execution may fail. Xargs can solve Note: file names or nouns with other meanings contain spaces. Combination of find and xargs: find | xargs COMMAND example
Ls | xargs rm deletes a large number of files in the current directory
Find / sbin/-perm + 700 | ls-l this command is incorrect
Find / bin/-perm / 7000 | xargs ls-Sl looks for files with special permissions and sorts them
Find / bin/-perm-7000 | xargs ls-Sl what is the difference between this command and the above command?
Find-type f-name "* .txt"-print0 | xargs-0 rm is separated by the character nul
Delete all files that begin with l
Build ten users at a time
Separated by the character 0
Find example
Back up the configuration file and add the .orig extension
Find-name "* .conf"-exec cp {} {} orig\;
Prompt to delete temporary files of joe that have existed for more than 3 days
Find / tmp-ctime + 3-user joe-ok rm {}\;
Look for files in the home directory that can be written by other users
Find ~-perm-002-exec chmod Omurw {}\;
Find ordinary files with the permission of 644 and suffix sh under / data, and increase the execution permission
Find / data-type f-perm 644-name "* .sh"-exec chmod 755 {}\;
View the directory of / home
Find / home-type d-ls
Compression, decompression and archiving tool compress/uncompress-d decompression, equivalent to uncompress
-c output the result to standard output without deleting the original file
-v display details uncompress file.Z decompress zcat file.Z to view the contents of the text file without explicit decompression
Example: zcat file.Z > file example
Compress: compressing m.txt files
Compress-d: decompress
Caompress-c: compress and retain the original file
Zcat: view the contents of unextracted files
Gzip/gunzip-d decompression, which is equivalent to gunzip
-c output the result to standard output, leaving the original file unchanged
-# specify compression ratio. The value of # is 1-9. The greater the value, the greater the compression ratio. Gunzip file.gz decompress zcat file.gz without explicit decompression to view the text file content .
Example: gzip-c messages > messages.gz gzip-c-d messages.gz > messages zcat messages.gz > messages cat messages | gzip > m.gz example
Gzip: compressing files
Gzip-9: the higher the value, the greater the degree of compression.
Gzip-d: extract files
Gunzip m.txt.gz: extracting files
Bzip2/bunzip2/bzcat-k keep, keep the original file
-d decompression
-# 1-9, compression ratio. Default is 9bunzip2 file.bz2 decompression bzcat file.bz2 without explicit decompression to view the text file content example
Bzip2: compressing files
Bzip2-k: compress and retain the original file
Bzip2-d: decompress
Bzcat: view the contents of unextracted files
Xz/unxz/xzcat-k keep, keep the original file
-d decompression
-# Compression ratio. Value is 1-9. Default is 6 unxz file.xz decompression xzcat file.xz without explicit decompression to view text file content examples.
Xz: compressing files
Unxz m.xa: decompression
Zip/unzip Packaging Compression
zip-r / backup/sysconfig / etc/sysconfig/ unpacking and decompression
unzip sysconfig.zip
cat / var/log/messages | zip messages-
unzip-p message.gz > message-p means pipe
Zip: package compression
Unzip: unpack
Tar (1) creates an archive with reserved permissions
tar-cpvf / PATH/FILE.tar FILE...
(2) append files to archives: note: appends to compressed files are not supported.
tar-r-f / PATH/FILE.tar FILE...
(3) View the list of files in the archive file
tar-t-f / PATH/FILE.tar
(4) start filing
tar-x-f / PATH/FILE.tar
tar-x-f / PATH/FILE.tar-C / PATH/
(5) implement with compression tools: archive and compress -j: bzip2,-z: gzip,-J: xz--exclude excluded files
tar zcvf / root/a3.tgz-- exclude=/app/host1-- exclude=/app/host2 / app -T option specifies the input file-X option specifies the list of files to exclude
tar zcvf mybackup.tgz-T / root/includefilelist-X / root/excludefilelist split: split a file into multiple files
splits large tar files into multiple small files
split-b Size-d tar-file-name prefix-name
split-b 1m-d mybackup.tgz mybackup-parts
split-b 1m mybackup.tgz mybackup-parts
merge:
cat mybackup-parts* > mybackup.tar.gz example
Tar cvf: package / var/log named log.tar
Tar tf: preview file list
Tar xvf: unpack any compression:
Unzip to the / tmp directory
Tar zcvf: packaged and compressed
Cpio function: package file or unpack cpio command is a tool to package and restore files through redirection. It can extract files ending in ".cpio" or ".tar" cpio [option] > file name or device name cpio [option]
< 文件名或者设备名 选项 -o output模式,打包,将标准输入传入的文件名打包后发送到标准输出 -i input模式,解包,对标准输入传入的打包文件名解包到当前目录 -t 预览,查看标准输入传入的打包文件中包含的文件列表 -O filename 输出到指定的归档文件名 -A 向已存在的归档文件中追加文件 -I filename 对指定的归档文件名解压 -F filename 使用指定的文件名替代标准输入或输出 -d 解包生成目录,在cpio还原时,自动的建立目录 -v 显示打包过程中的文件名称示例 将etc目录备份: find ./etc -print |cpio -ov >Bak.cpio
Append / data content to bak.cpio
find / data | cpio-oA-F bak.cpio
Content preview
cpio-tv < etc.cpio
Unpack a file
cpio-idv < etc.cpio
Preview the list of files in the packaged file
Unpack the generation directory
Practice
Count the number of lines of all .c suffix files in the operating system
Count the number of lines of code in c language in the operating system
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.