Find basic commands in Linux

Source: Internet
Author: User

1. search for files using the Find command

Find command: In real-time search on the local file system, the user who invokes the command must have read and execute permissions to the directory where the content is to be viewed. Search the entire system, then use the start directory/. The first parameter to find is the directory to search for, and if the search directory is omitted, the search starts from the current directory and finds matches in any subdirectory.

General form of the 2.Find command: Find Pathname-options

Pathname represents the directory path that is being looked for,/represents the system root directory

The options are commonly used with the following:

A. search by file name (-name)

Example: [[email protected] ~]# find/tmp/file2-name file2

/tmp/file2 ()

[Email protected] ~]# Find/-name sshd_config

/etc/ssh/sshd_config (Start search from the current root directory)

[[email protected] ~]# Find/-name "*.txt" (use wildcards to search for file names)

/etc/pki/nssdb/pkcs11.txt

/etc/brltty/brl-lt-all.txt

/etc/brltty/brl-mb-all.txt

/etc/brltty/brl-md-all.txt

/etc/brltty/brl-mn-all.txt

/etc/brltty/brl-ba-all.txt

Note: If the file name you are searching for is not case sensitive, use-iname "

B. Search by Owner (-user-group-uid-gid)

Example: [[email protected] desktop]$ Find-uid 1000

.

./lili

[[email protected] ~]# Find/-user root-group Mail

/var/spool/mail

/var/spool/mail/root

c. Search by specific permission set (-perm) "Specific permissions available on behalf of the octal number 4, 2, 1 for each permission"

[email protected] ~]# find/home-perm 664 ( match user has read, write permission, group member has read, write permission, other has Read permission)

/home/user/.config/gtk-3.0/bookmarks

/home/user/.config/gnome-initial-setup-done

/home/user/.config/yelp/yelp.cfg

/home/user/.cache/abrt/applet_dirlist

/home/user/.cache/tracker/miner-applications-locale.txt

/home/user/.cache/tracker/last-crawl.txt

/home/user/.cache/tracker/first-index.txt

/home/user/desktop/lili

"Note: Digital permissions before/means at least one of the users, groups, other people who match the file, equals or relationships, and before the digital permission-indicates that all three instances must exist, equivalent to the relationship; when used with/or, the 0 value resembles a wildcard"

[email protected] desktop]$ find-perm -004

.

./lili

d. Search by specified size (-size units are: K stands for kilobytes m for megabytes G for gigabytes)

Find-size Size "+ number, indicating greater than the file;-number, representing less than file"

[email protected] ~]# find-size -1k

./.local/share/gnome-settings-daemon/input-sources-converted

./.local/share/folks/relationships.ini

./.local/share/.converted-launchers

./.local/share/tracker/data/.meta.isrunning

./.local/share/keyrings/user.keystore.b52tqx

E. Search by file change Time "-mmin in minutes-mtime in days"

Find-mmin Time "Example: 120 indicates a file that was modified exactly 120 minutes ago; +120 means a file modified 120 minutes ago;-120 files modified less than 120 minutes ago"

[Email protected] ~]# find/tmp-mmin-240

/tmp

/tmp/. X11-unix

/tmp/. X11-unix/x0

/tmp/. Ice-unix

/tmp/. ice-unix/3016

/tmp/.esd-1000

/tmp/.esd-1000/socket

/tmp/systemd-private-2xv5n9

/tmp/systemd-private-2xv5n9/tmp

/tmp/. X0-lock

/tmp/systemd-private-wliqkz

/tmp/systemd-private-wliqkz/tmp

/tmp/ssh-wu8ircyhwtvo

/tmp/ssh-wu8ircyhwtvo/agent.3016

/tmp/systemd-private-pkqdal

/tmp/systemd-private-pkqdal/tmp

/tmp/file2

.....

F. Search by given file type (-type)

Find/-type f/matching file type is normal file

Find/-type d/matching file type is directory

Find/-type L/matching file type is soft connection "-links+n represents a file with a specific hard link, +n represents a file with a hard link number greater than n, and-n indicates a file with a hard-link number less than n"

Find/-type b/matching file type is block device

[[email protected] ~]# Find/-type b

/dev/sda2

/dev/sda1

/dev/sda

3. use exec to execute the command "Basic command:-exec with the executed command {} \; where the executed command can be ls-l list, rm-rf Delete, cp-a copy, etc., \; Just a syntax representation"

[[email protected] ~]# Find/-type f-exec ls-l {} \; (means to list all ordinary files in the current directory that are matched to)

-R--------. 1 User User 67108904 Nov 19:23/dev/shm/pulse-shm-74798595

-R--------. 1 User User 67108904 Nov 19:22/dev/shm/pulse-shm-2901993750

-R--------. 1 User User 67108904 Nov 19:22/dev/shm/pulse-shm-2662806495

-R--------. 1 User User 67108904 Nov 19:39/dev/shm/pulse-shm-4161240769

-R--------. 1 User User 67108904 Nov 19:39/dev/shm/pulse-shm-3144017989

-R--------. 1 GDM GDM 67108904 Nov 19:21/dev/shm/pulse-shm-1648396760


Find basic commands in Linux

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.