Linux file search and compression common knowledge summary

Source: Internet
Author: User
Tags ziparchive

First, File search

1.locate command: Locate keyword common options:    -i  perform case-sensitive search     -n   n only lists the pre-built file index database on the first n matching items query system on:/var/lib/mlocate/mlocate.db, because the index is established beforehand, so the search speed is fast. 2.find command: Real-time search tool, through the path of the specified paths to complete the file lookup, query speed slightly slower, accurate search, real-time search. It is possible to search only directories where the user has read and execute permissions. find - search for files in a directory hierarchyfind [-h] [- L] [-p] [-d debugopts] [-olevel] [path ...]  [expression]find [option]... [Find path] [find condition] [processing action]  Find path: Specify specific target path; default to current directory   Search criteria: The specified search criteria, can be file name, size, type,   permissions, such as standards; The default is to find all files under the specified path   processing action: to the conditions of the file, the default output to the screen 1) based on the file name and Inode lookup      -name  "file name": Support wildcard  *,? [],[^]    -iname  "file name": Case insensitive     -inum n  Search by inode number  2) Search by genus, genus:     -user username: Search by username     -group  GroupName: Find      -uid by group name: Search by UID     &nbsP;-gid: Search by GID      -nouser: Find files that are not master      -nogroup: Find non-group files  3) file type find-type:  by file type find      f:  normal file       d:  Directory      b:  block devices      c:  character devices       l:  Symbolic link Files      p:  Named pipes       s:  socket     4) combination conditions (Morgan Law)     -a:  with, while satisfying      -o:  or,     -not, !: Non, take anti      non A, and   non b:  non-(A or B)              -not  ( -user hadoop -o  -iname  "*.txt"  )      non-A, or   non-b:  (A and B) instances:     ! a -a ! b = ! (a -o b)     ! a -o ! b = ! (a -a b)     find -name  "file.txt"      find -iname  "file.txt"      find / -name  "*.txt"      find /var/ -name   "*log*"      find -user alren -group gentoo       find -user chen -not group chen       find -user gentoo -o -user archlnux     find /- User alren -o -uid 1001     find -not \ (-user chen  -o -user alren\) equivalent to Find -not -user chen -a -not -user alren  5) file size find      -size [+|-] #UNIT            Common units:k, m, g      #UNIT:  (#-1, #]           as:6k  (5k,6k]     -#UNIT:[0,#-1]           as:-6k  means [0,5k]     + #UNIT: (#,∞)            such as:+6k  (6k,∞) 6) timestamp lookup    based on time stamp:  in "days" as a unit;  the following #=1 as an example-atime [+| -]#,  #: [#,#+1)  find /etc/ -atme 1 : represents greater than or equal to 1 days, less than 2 days time period is visited; +#: [#+ 1,∞] find /etc/ -atime +1 : Indicates that one day, including one day, has been visited-#: [0,#)   find /etc/  -atime -1 : Indicates that the;-mtime -ctime  was visited a day ago in minutes:  -amin -mmin - cmin7) Search by permissions:-perm [+|-]mode    mode: Exact Match     +MODE:  Any one of a class of users to match, often used to find a certain type of user's specific permissions exist (cetos6.x);     /mode: Any class of User (U,g,o) object permissions as long as one can match, or relationship, +   Start-out from Centos7      -MODE:  each class of users specifies that the permission bits to check match, or the relationship;    find  -perm 755  Match permission mode is exactly 755File      as long as any person has write permission, find -perm +222 will match        such as:  find /var/ -perm +222  or find /var/ -perm /222  can be matched as long as any user has permission to write     find -perm -222 matches only when everyone has write permissions       such as: find -perm  -222  only when everyone has Read permission can it be matched to     find -perm -002   matches when other people (other) have write permissions       can match to     if only other people have read permissions, such as:find /var/ -perm -002    Handling Action:-print: Default processing action, display value screen-ls: similar to executing ls -l command on found file  -delete: Delete found file  -exec command  {} \; Execute command-specified commands on each file found the command does not accept too many arguments, and the command execution may fail, as follows to circumvent this problem     find | Xargs command fidn instance:find -name  "*.conf"  -exec cp {} {}.com \;   #备份配置文件, and renamed find /tmp -ctime +3 -user chen -ok -rm {} \;# Prompt to delete Chen user temporary files that exist longer than three days find ~ -perm -002 -exec chmod o-w {} \;  #在你的主目录中寻找可被其它用户写入的文件  find  /data –type  f -perm 644  -name  "*.sh"  –exec chmod  755 {} \; find  /home –type d -|xargs rm -rf

Ii. compression, decompression and archiving tools

gzip Command:

1) gzip Command:    gzip [option]... file ...           options:             -d: Unzip, equivalent to Gunzip               -C: Outputs compressed or decompressed results to standard output [[ email protected] ~]# gzip -c awk.txt >awk.gz[[email protected] ~]#  lsawk.gz  awk.txt  passwd  test.sh  test.x[[email protected ] ~]# gzip -c passwd >passwdddddd.gz[[email protected] ~]# lsawk.gz   awk.txt  passwd  passwdddddd.gz  test.sh  test.x[[email  protected] ~]# gunzip passwdddddd.gz[[email protected] ~]# lsawk.gz   awk.txt  passwd  passwdddddd  test.sh  test.x[[email  Protected] ~]# gzip -d awk.gz[[email protected] ~]# lsawk  awk.txt  passwd   passwdddddd  test.sh  test.x[[email protected] ~]#

Bzip2 command:

2) bzip2 Command:bzip2 [option]... file ...     -k: keep,  keep the original file      -d: Unzip  [[email protected] ~]# lsawk  awk.txt   passwd  passwdddddd  test.sh  test.x[[email protected] ~]#  bzip2 -k passwd[[email protected] ~]# lsawk  awk.txt  passwd   passwd.bz2  passwdddddd  test.sh  test.x[[email protected]  ~]# bzip2 passwdddddd[[email protected] ~]# lsawk  awk.txt   passwd  passwd.bz2  passwdddddd.bz2  test.sh  test.x[[email  protected] ~]# bunzip2 passwdddddd.bz2[[email protected] ~]# lsawk   awk.txt  passwd  passwd.bz2  passwdddddd  test.sh   test.x[[email protected] ~]#&Nbsp;bunzip2 -d passwd.bz2bunzip2: output file passwd already exists. [[email protected] ~]# lsawk  awk.txt  passwd  passwd.bz2   passwdddddd  test.sh  test.x[[email protected] ~]# mv passwd  passwd1[[email protected] ~]# bunzip2 -d passwd.bz2[[email protected]  ~]# lsawk  awk.txt  passwd  passwd1  passwdddddd   test.sh  test.x[[email protected] ~]#

Zip command:

3) Zip command:    zip - package and compress  (archive)  files     1) package         zip  package file name    files to package          ZIP PASSWD.ZIP PASSWD    2) Decompression          unzip .zip End of File          unzip passwd.zip [email protected] ~]# lsawk  awk.txt  passwd   passwd1  passwdddddd  test.sh  test.x[[email protected] ~] # zip -r passwd.zip passwd  adding: passwd  (deflated 63%) [[Email  protected] ~]# lsawk  awk.txt  passwd  passwd1   passwdddddd  passwd.zip  test.sh  test.x[[email protected] ~]#  Unzip passwd.ziparchiVe:  passwd.zipreplace passwd? [y]es, [n]o, [a]ll, [n]one, [r]ename:  y  inflating: passwd[[email protected] ~]# lsawk  awk.txt   passwd  passwd1  passwdddddd  passwd.zip  test.sh   Test.x[[email protected] ~]# rm -f passwd[[email protected] ~]# unzip  passwd.ziparchive:  passwd.zip  inflating: passwd[[email protected] ~ ]# lsawk  awk.txt  passwd  passwd1  passwdddddd   Passwd.zip  test.sh  test.x

Tar command:

Archive Tool:   tar [options] -f file.tar file1 ...      -c:  Create an archive      -x:  expand an archive      -t:  View archived files without expanding      -V: show the process of creating compression or decompression     tar -cvf  archive.tar file1  Create a non-compressed  tarball     tar -cvf archive.tar  file1 file2 dir1  Create an archive file containing ' file1 ', ' file2 ' and ' Dir1 '      tar  -tf archive.tar  Display the contents of a package      tar -xvf archive.tar  Release a package      tar -xvf archive.tar -C /tmp  release the compressed package to the  /TMP directory      tar -cvfj archive.tar.bz2 dir1  Create a compressed package in BZIP2 format       tar -xvfj archive.tar.bz2  unzip a BZIP2-formatted compression package      tar  -cvfz archive.tar.gz dir1  Create a zipped package in gzip format      tar -xvfz archive.tar.gz  unzip an gzip-formatted compression 
[[email protected] ~]# lsawk  awk.txt  passwd  passwd1   passwdddddd  passwd.zip  test.sh[[email protected] ~]# tar -zcvf  passwd.tar.gz passwdpasswd[[email protected] ~]# lsawk  awk.txt   passwd  passwd1  passwdddddd  passwd.tar.gz  passwd.zip   test.sh[[email protected] ~]# tar -jcvf passwd.tar.bz2 passwdpasswd[[email  protected] ~]# lsawk      passwd   passwdddddd      passwd.tar.gz  test.shawk.txt  passwd1   passwd.tar.bz2  passwd.zip[[email protected] ~]# tar -zxvf  passwd.tar.gzpasswd[[email protected] ~]# lsawk      passwd    passwdddddd     p asswd.tar.gz  test.shawk.txt  passwd1  passwd.tar.bz2  passwd.zip[[ Email protected] ~]# rm -f passwd[[email protected] ~]# tar -zxvf  passwd.tar.gzpasswd[[email protected] ~]# lsawk      passwd    passwdddddd     passwd.tar.gz  test.shawk.txt   passwd1  passwd.tar.bz2  passwd.zip[[email protected] ~]# rm -f  Passwd[[email protected] ~]# tar -jxvf passwd.tar.bz2passwd[[email protected]  ~]# lsawk passwd passwdddddd passwd.tar.gz test.shawk.txt passwd1  Passwd.tar.bz2 passwd.zip


Third, the actual practice of small exercises

1. Find the main root of the/var directory and all files belonging to the group Mail  [[email protected] ~]# find /var/ -user  root-a  -group mail/var/spool/mail/var/spool/mail/root/var/spool/mail/rooter[[email  Protected] ~] #2, find all files that are not root, LP, GDM under the/var directory  [[email protected] ~]# find /var/  -not \ ( -userroot -o -user lp -o -user gdm \) |wc -l125 [[Email protected] ~]# find /var/ -not -userroot -a -not -user  lp -a -not -user gdm |wc -l125[[email protected] ~]# 3, Find/ The contents of the Var directory have been modified in the last week and are not  root or postfix files  [[email protected]~]# find /var/ - mtime -7 -a -not -user root -a -not -user  postfix/var/lib/ Setroubleshoot/setroubleshoot_database.xml/var/spool/abrt/ccpp-2016-07-19-15:47:15-3568[[email protected]  ~]# find /vAr/ -mtime -7 -not \ ( -user root -o  -user postfix \)/ var/lib/setroubleshoot/setroubleshoot_database.xml/var/spool/abrt/ccpp-2016-07-19-15:47:15-3568[[email  Protected] ~]# 4, find files that are not owned or owned by the current system, and have been interviewed   asked in the last week  [[email protected] ~]#  Find / \ ( -nouser -o-nogroup \)  -a -atime -7find:  '/proc/8419/ Task/8419/fd/6 ': no suchfile or directoryfind:  '/PROC/8419/TASK/8419/FDINFO/6 ':  nosuch file or directoryfind:  '/PROC/8419/FD/6 ': no such file  ordirectoryfind:  '/PROC/8419/FDINFO/6 ': no such fileor directory[[email  Protected] ~]# 5, find all files that are larger than 1M in the/etc directory and are of the normal file type  [[email protected] ~]# find / etc/ -size +1m  -type f/etc/selinux/targeted/policy/policy.29/etc/udev/hwdb.bin/etc/ brltty/zh-tw.ctb[[email protected] ~]# 6, find files with no write permission for all users in/etc directory  [[email protected] ~]# find /etc/   -not -perm  /222[[email protected] ~]# find /etc/ -not - perm  +222 [[email protected] ~]# find /etc/ -not -perm   /222 |wc -l23[[email protected] ~]# find /etc/ -not -perm + 222 |wc -l23[[email protected] ~] #7, find at least one class of users who do not have permission to execute files in/etc directory  [[email protected]  ~]# find /etc/ -not-perm  -1118, find the/ETC/INIT.D directory, all users have execute permissions, and other users have write permissions files [[email  protected] ~]# find /etc/init.d/ -perm-113

Small series summary also hard, if think also can, handy point a praise:) ....

This article is from "Wake up your not alarm clock but dream" blog, please be sure to keep this source http://purify.blog.51cto.com/10572011/1838930

Linux file search and compression common knowledge summary

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.