Linux Tenth Day: (August 15) file lookup and compression

Source: Internet
Author: User
Tags file copy unpack

Linux Tenth Day: (August 15) file lookup and compression

Locate non-real-time lookup (database lookup)/var/lib/mlocate/mlocate.db
Locate-i performing a case-sensitive search
Locate-n N lists only the first n matching items
Locate Foo search for a file with "foo" in the name or path
Locate-r ' \.foo$ ' uses Regex to search for files ending with ". Foo"

Find-name "file name" support using Glob *,?, [], [^]
Find-iname "file name" does not distinguish between letter case
Find-inumn Search by Inode number
Find-samefilename files with the same inode number
Find-links n files with number of links n
Find-regex "pattern" matches the entire file path string with pattern, not just the file name

Find-user USERNAME Find a file that belongs to the specified user (UID)
Find-group GRPNAME to find files belonging to the specified group (GID)
Find-uiduserid to find files that belong to the specified UID number
Find-gidgroupid find a file with the specified GID number for the genus Group
Find-nouser finding files that are not owned by the master
Find-nogroup finding files that are not owned by a group

Find-type F: Normal file
Find-type d: Catalog file
Find-type L: Symbolic Link file
Find-type S: Socket file
Find-type B: Block device files
Find-type C: Character device files
Find-type P: Piping file

Combination conditions
And-A
Or-O
Non--not,!

De Morgan's law.
(non-P) or (non-Q) = Non (P and q)
(Non-P) and (non-Q) = Non (p or Q)
! A-a! B =! (A-o B)
! A-o! B =! (A-a B)

Find-name snow.png to search for files named Snow.png
Find-iname snow.png search file without case
Find-user joe-group Joe Search user Joe group Joe's File


Find 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

Find all other files in the. conf suffix under/etc/except the/ETC/SANE.D directory
Find/etc-path '/ETC/SANE.D '-a-prune
-o-name "*.conf"-print


-size [+|-] #UNIT find common units by file size K, M, G
#UNIT: (#-1, #] 6k = (5k,6k]
-#UNIT [0,#-1] -6k = [0,5k]
+ #UNIT (#,∞) +6k representation (6k,∞)


Based on time stamp
Take "Day" as the unit;
-atime[+|-]#,
#: [#,#+1]
+#: [#+1,∞]
-#: [0,#]
-mtime
-ctime
In "Minutes" units
-amin
-mmin
-cmin


-perm [/|-]mode based on permissions lookup
MODE: Exact permission match
/mode the permissions of any class (U,g,o) object as long as it can be a match, or relationship, + from the CENTOS7 start elimination
-mode each class of objects must have both the specified permission and the relationship
0 indicates no concern
Find-perm 755 Matching permission mode is exactly 755 of the file
Find-perm + 222 Only when anyone has write permission
find-perm-222 only when everyone has write permission
Find-perm-002 only if other people (other) have write permission

-print Default processing action, display to the screen;
-ls is similar to performing a "ls-l" command on a found file
-delete delete the found file;
-flsfile long format information for all files found in the specified file
-ok COMMAND {} \; Executes commands specified by command on each file found, and interactively asks the user to confirm each file before executing the command
-exec COMMAND {} \; Executes command-specific commands {} for each file found: used to refer to the file name itself
Find passes the found file to the command specified later, and finds all eligible files once passed to the following command
Some commands cannot accept too many parameters, at which point the command execution may fail, and the following ways can circumvent this problem
Find | Xargscommand

Example demonstration
Find-name "*.conf"-exec cp {} {}.org \; Backup configuration file, Add. orig this extension
find/tmp-ctime+3-userjoe-okrm{}\; Prompt to delete temporary files for Joe that are older than 3 days long
find~-perm-002-execchmodo-w{}\; Find files in your home directory that can be written by other users
Find/data–type f-perm 644-name "*.sh" –exec chmod 755 {} \;
Find/home–type D-ls

compress [-DFVCVR] [-B maxbits] [file ...]
-D: uncompressed, equivalent to
-C: Result output to standard output, do not delete original file
-V: Show details
Uncompress decompression
Zcatfile. Z>file


Gzip[option] ... FILE ...
-D: Uncompressed, equivalent to Gunzip
-C: Output the compressed or decompressed results to standard output
-#1-9, specify the compression ratio, the larger the value, the greater the compression ratio
Zcat View text file contents without explicit decompression
GZIP-C Messages >messages.gz
Gzip-c-D messages.gz > messages
zcatmessages.gz > Messages


bzip2 [OPTION] ... FILE ...
-k:keep, keep the original file
-D Decompression
-#1-9, compression ratio, default is 6
Bzcat View text file contents without explicit decompression


Xz[option] ... FILE ...
-k:keep, keep the original file
-D Decompression
-#1-9, compression ratio, default is 6
Xzcat: View text file contents without explicit decompression


Packaging compression
Zip–r sysconfigsysconfig/
Unpacking and decompression
Unzip Sysconfig.zip
Cat/var/log/messages | Zip Message-
UNZIP-P Message > Message


tar [OPTION] ...
(1) Create an archive
Tar-c-f/path/to/somefile.tar FILE ...
Tar Cf/path/to/somefile.tar FILE ...
(2) View the list of files in the archive file
Tar-t-f/path/to/somefile.tar
(3) Expand archive
Tar-x-f/path/to/somefile.tar
Tar-x-f/path/to/somefile.tar-c/path/
Archive and compress with compression tools
-J:BZIP2,-z:gzip,-J:XZ


The Cpio command is a redirected way of packaging a file for backup, restoring a recovery tool that can decompress files ending with ". Cpio" or ". Tar".
cpio[Options] > file name or device name
cpio[Options] < file name or device name
-o Package a file copy into a file or export the file to the device
-I unpack, unzip the package file or restore the backup on the device to the system
-T Preview, view the contents of the file or output to the file on the device
-V Displays the file name during the packaging process.
-D Unpack the directory, and automatically build the directory when Cpio restore
-C A newer storage method

Find./etc-print |cpio-ov>etc.cpio to back up the ETC directory
cpio–tv< Etc.cpio Content Preview
Cpio–iv <etc.cpio to unpack the file
Cpio–idv <etc.cpio

Linux Tenth Day: (August 15) file lookup and compression

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.