Linux-find Find

Source: Internet
Author: User

Lead:
which
Whereis
Locate
Find

Find
which can only query commands
#which rpm

Whereis
You can query the location of commands and configuration files
#whereis rpm
#whereis passwd

Whatis
#whatis rpm with the same effect as the following command, the query rpm command in which chapter man has explained
#man-F rpm

Find
#find path condition-dependent operator [-exec|-ok Action]
Path
The default path is not written when you are looking for current paths
Cases:
/etc
./
/
/var/ftp

Conditions
Name Size time file type user group permissions ...

-name file name lookup by name

Find/-name A.txt
#find / -name a.t?? find / -name a.tx?#find / -name ‘*a.txt‘ find / -iname ‘*a.txt‘

-iname Case insensitive

? Represents a single character
* Denotes all characters

In general, {} cannot be used
{1..100}
{ABC,ABD,EFG}

Wildcard characters:

    • ? [] {}
    • Represents all characters
      ? Represents any single character
      [] denotes any one of these single characters
      Cases:
      [ABC]
      [A-z]
      [A-z]
      [A-za-z]
      [!a-z]! Take the reverse
      [0-9]

      A to Z match order is aabbcc ...
      [[email protected] python]# ls
      A.txt E.txt j.txt N.txt s.txt W.txt
      A.txt f.txt J.txt o.txt S.txt x.txt
      B.txt F.txt k.txt O.txt t.txt X.txt
      B.txt g.txt K.txt p.txt T.txt y.txt
      C.txt G.txt l.txt P.txt u.txt Y.txt
      C.txt h.txt L.txt q.txt U.txt z.txt
      D.txt H.txt m.txt Q.txt v.txt Z.txt
      D.txt i.txt M.txt r.txt V.txt
      E.txt I.txt n.txt R.txt w.txt

      {Hello,hi,king,xiaoxuan}
      #touch {Python,wing,haha}.txt
      {A.. Z
      {1..100}
      /dev/vdc{1,2,3}

Find by size
-size
#find/-size 50M
#find/-size +50m
#find/-size-50m
Find more than 10M less than 20M
#find/-size +10m-a-size-20m

-A can be replaced with-and
#find/-size-10m-o-size +20m

-O can be replaced with-or
Find./! -size-10m
Find/-size-50m-a-name "Wing"
Find/! (-size-50m-a-name "Wing")
! Take counter

( )
\ escape character to make a meaningful change meaningless make sense of the meaningless

Add: Test data with dd command
#dd If=/dev/zero of=/tmp/aa.txt bs=5m count=2

Find by File type
-type
F
D
B
C
L
S
P
#find/-type c-exec ls-l {} \;

#find/tmp/-name aa.txt-exec rm-i {} \;
find/tmp/-name aa.txt-ok rm {} \;
< RM .../tmp/aa.txt >? Y

-exec further operations on previously found files
-ok and-exec, just a few hints

Search by permissions:
-perm
Find./-perm 644-ls
./dd.txt

Find by users and groups
-user
-group
#find./-user Wing
./bb.txt
Find./-group User3
./cc.txt

by Time
-atime Access Time
-mtime Modify Time
-ctime Change Time
-amin
-mmin
-cmin

Time indicates the unit is day
Min means minute
#stat file

Find files accessed within two minutes
#find/tmp-amin-2
/tmp/a.txt

Find files accessed two minutes ago
Find/tmp-amin +2

To find a hard link to a file:
ln a.txt Heihei
#ll-I.
439360-rw-r--r--2 root root 22:22 a.txt
439360-rw-r--r--2 root root 22:22 Heihei
Find. -samefile A.txt
./a.txt
./heihei

Specify the directory depth to find:
-maxdepth levels
-mindepth levels
Find/-maxdepth 3-a-name "Ifcfg-eth0"

Find by Regular expression:
Find/etc-regex '. *ifcfg-ens[0-9][0-9] '

-exec -ok#find . -name wing.txt -exec cp {}  /root/Desktop/ \;防止被查找到的文件过多,导致内存溢出错误 find  .  -name wing.txt | xargs  -i cp {} /root/Desktop

Linux-find Find

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.