Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does linux find files using the locate and find commands?

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1 locate lookup file using updatedb to establish mlocate.db entire disk file search index affects disk performance.

Locate-I is case-insensitive

Locate-n lists only the first n

Locate-r ". (jpg | png) $" find files ending in jpg or png support j basic regular expressions

2 find real-time search default recursive search

Find [OPTION]... [search path] [search condition] [processing action]

/ etc/passwd-maxdepth specifies the search level this example searches for passwd in the directory 1 below / etc/.

Find / etc/-maxdepth 2-mindepth 2-name filename search up to the second layer at least search the second layer only the second layer

[23:54:08 root@localhost ~] $find / data-depth lists the files first and then lists the folders with changes in arrangement

/ data/scripts37/diskcheck1026.sh

/ data/scripts37/creatuseradd.sh

/ data/scripts37/read23.sh

.

/ data/f1.txt

/ data/dir/f1

/ data/dir

/ data/f2

/ data

-iname "file name": case-insensitive

[00:02:27 root@localhost data] $ll-I

Total 68

100663360 drwxr-xr-x. 2 root root 16 Feb 16 23:51 dir

69-rw-r--r--. 1 root root 0 Feb 16 20:51 f1.txt

85-rw-r--r--. 1 root root 595 Feb 16 23:51 f2

68 drwxr-xr-x. 2 root root 4096 Feb 16 23:13 scripts37

67-rw-r--r--. 1 root root 61440 Feb 16 08:17 scripts37.tar

33554496 drwxr-xr-x. 3 root root 19 Feb 16 15:28 test

[00:02:33 root@localhost data] $find / data/-inum 70

/ data/scripts37/diskcheck1026.sh

[00:06:25 root@localhost data] $ll-I

Total 72

100663360 drwxr-xr-x. 2 root root 16 Feb 16 23:51 dir

69-rw-r--r--. 1 root root 0 Feb 16 20:51 f1.txt

85-rw-r--r--. 2 root root 595 Feb 16 23:51 f2

85-rw-r--r--. 2 root root 595 Feb 16 23:51 f2.link

68 drwxr-xr-x. 2 root root 4096 Feb 16 23:13 scripts37

67-rw-r--r--. 1 root root 61440 Feb 16 08:17 scripts37.tar

33554496 drwxr-xr-x. 3 root root 19 Feb 16 15:28 test

[00:06:35 root@localhost data] $find / data/-samefile / data/f2

/ data/f2

/ data/f2.link

[00:07:08 root@localhost data] $

-regex "PSTTERN": matches the entire file path with PATTERN. Not the file name.

00:10:50 root@localhost data] $find / usr/share/pixmaps/-regex ". * .jpg $"-match completion path

Find / etc-type d search, folder under etc

Find, dev-type b search for block files

Find / data-empty-ls search empty file capitalization is zero

[00:22:44 root@localhost data] $find / data/-empty-ls

69 0-rw-r--r-- 1 root root 0 Feb 16 20:51 / data/f1.txt

Find / data!-empty-ls search for non-empty files! Logic inversion

Find / data-not-empty-ls search for non-empty files

And:-a

Or:-o

Non:-not!

# find / data!-empty-ls-check non-empty files and folders

# find / data-not-empty-ls-check non-empty files and folders

Find / data-name "f"-a-type f lookup starts with f and is a normal file-a can be omitted by default and mode

Find / data-name "f

Find / data-name "f"-o-type f looks for files that start with f or are ordinary files

# find / etc-path'/ etc/sane.d'-a-prune-o-name ".conf"-an and-prune cut the etc/sane.d/ directory and search for .conf files under / etc.

* find / etc (- path "/ etc/sane.d"-o "/ etc/fonts")-a-prune-o-name ".conf" search for files ending in .conf under / etc except, etc/sane.d folder and, etc/fonts folder * *

10240500 records in

10240500 records out

10240 bytes (10 kB) copied, 0.140448 s, 72.9 kB/s

[03:23:35 root@localhost data] $ll F1

-rw-r--r--. 1 root root 10240 Feb 17 03:23 f1

[03:23:41 root@localhost data] $find-size 10k

. / f1

[03:24:06 root@localhost data] $

# find / etc/-szie-6k {find files between 0-5K}

# find / etc/-size + 6k {find files greater than 6k}

Find-atime (default is in days) + 10-10 days old files

Find-atime 10 finds files between the tenth and eleventh days. The unwritten path defaults to the current path

Find-perm 644 finds the exact match of file permissions for the current 644

[04:17:32 root@localhost data] $find-perm-22222

[04:17:49 root@localhost data] $ll

Total 80

Drwxr-xr-x. 2 root root 16 Feb 16 23:51 dir

Drwxr-xr-x. 2 root root 6 Feb 17 00:23 dir2

-. 1 root root 10240 Feb 17 03:23 f1

-rw-r--r--. 1 root root 0 Feb 16 20:51 f1.txt

-rw-r--r--. 1 root root 595 Feb 16 23:51 f2

Lrwxrwxrwx. 1 root root 8 Feb 17 00:08 f2.link-> / data/f2

Equivalent command

[04:38:24 root@localhost data] $find-perm-001 > / data/ls.log

[04:42:48 root@localhost data] $find-perm / 001-ok chmod otakw {}\; find the file and modify the permissions "{}" to get the result-ok must end the syntax requirement with "\;"

< chmod ... ./scripts37 >

? Y

< chmod ... ./scripts37/diskcheck1026.sh >

? Y

< chmod ... ./scripts37/creatuseradd.sh >

? Y

< chmod ... ./scripts37/age.sh >

? Y

< chmod ... ./scripts37/yesorno_case23.sh >

? Y

< chmod ... ./scripts37/count.sh >

? Y

< chmod ... ./scripts37/YESORNO23.sh >

? Y

< chmod ... ./scripts37/systeminfo23.sh >

? Y

< chmod ... ./scripts37/yesorno23.sh >

? Y

< chmod ... ./scripts37/checkdisk.sh >

? Y

< chmod ... ./scripts37/useDISK.sh >

? Y

< chmod ... ./scripts37/set.sh >

? Y

< chmod ... ./test >

? Y

< chmod ... ./test/test1 >

? Y

< chmod ... ./dir >

? Y

< chmod ... ./dir2 >

? Y

< chmod ... ./fid >

? Y

Drwxr-xrwx. 2 root root 16 Feb 16 23:51 dir

Drwxr-xrwx. 2 root root 6 Feb 17 00:23 dir2

-rw-r--r--. 1 root root 0 Feb 16 20:51 f1.txt

Drwxr-xrwx. 2 root root 6 Feb 17 00:35 fid

-rw-r--r--. 1 root root 1540 Feb 17 04:38 flog2.log

-rw-r--r--. 1 root root 325 Feb 17 04:42 ls.log

Drwxr-xrwx. 2 root root 4096 Feb 16 23:13 scripts37

-rw-r--r--. 1 root root 61440 Feb 16 08:17 scripts37.tar

Drwxr-xrwx. 3 root root 19 Feb 16 15:28 test

-rw-. 1 root root 28M Dec 14 08:31 / boot/initramfs-3.10.0-957.el7.x86_64.img

-rw-. 1 root root 11m Dec 14 08:32 / boot/initramfs-3.10.0-957.el7.x86_64kdump.img

Find / etc-name passwd-find + l path + specified file name

[23:42:14 root@localhost scripts37] $find / etc/-maxdepth 1-name passwd

/ data/scripts37.tar

-name supports wildcards such as-name "* .jpg"

-inum n look up by inode number

-samefile name files with the same inode number

-link n Files with n links

[00:13:17 root@localhost data] $find /-user zhonghua-ls-lists the file attributes by the ls of the file that the user searches for zhonghua.

Find /-nouser-find unowned files

67160128 0 drwxr-xr-x 2 root root 6 Feb 16 15:28 / data/test/test1

Support logical conditions

Find / data (- name "f *"-o-type f)-a ls-a default is that logic and priority are high so that priority commands are enclosed in parentheses and need to be escaped first.

~ # find / etc-name "* .conf"-"-" avoid errors

# exclude search

[03:22:12 root@localhost data] $dd if=/dev/zero of=f1 bs=1 count=10240-- create file F1 uppercase 10K bs=1 (1 byte) 1024 bytes is 1K, 10240 bytes is 10k

# find / etc/-size 6k {find uppercase files between 5 and 6K}

# find-atime-10 files within 10 days

[04:14:25 root@localhost data] $find / data/scripts37-perm / 622-ls fuzzy match / 622 is the group to which the owner belongs and other as long as there is a match.

. / f2.link-"means that both the group to which the owner belongs and the other must have write permission

[04:37:54 root@localhost data] $find-perm-001-fls / data/flog2.log

< chmod ... . >

? Y

[04:48:55 root@localhost data] $find-perm / 002-exec ls-l {}\; exec instead of OK no longer prompts for direct results

Total 72

[04:52:44 root@localhost data] $find /-size + 10m-exec ls-lh {}\

-rw-. 1 root root 71M Dec 14 08:29 / boot/initramfs-0-rescue-c8f47886da6d4ec687a38cc0be7425b1.img

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report