Use of common find commands in Linux

Source: Internet
Author: User
Tags gnupg gpg

The Linux Find command searches the directory structure for files and performs the specified actions. The Linux Find command provides quite a lot of search files and is very powerful. Because find has powerful features, it has a lot of options, and we need to take the time to understand it.

Command format:

Find Pathname-options [-print-exec-ok ...]

Command function:

Used to locate files in the file tree and make appropriate processing (possibly accessing the disk)

Command parameters:

The directory path that the Pathname:find command looks for. For example, use. To represent the current directory, and/to represent the system root directory.
The-print:find command outputs the matched file to standard output.
The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {} \;, note the space between {} and \;
-ok: The same as-exec, except that the shell command given by the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.

#-print output of the found file to standard output
#-exec command {} \; -the command operation for the file to be found, with spaces between {} and \;
#-ok and-exec are the same, except to consult the user before operation

When I perform a command operation, I first create a name file in Linux.

[[email protected] ~]$ mkdir name[[email protected] ~]$ lsdesktop Documents Downloads Music name Pictures public Te Mplates Videos

-name searches for files by file name.

[[Email protected] ~]$ lsdesktop  documents  downloads  music   name  Pictures  Public  Templates  Videos[[email  protected] ~]$ find -name name  //find a file named name./name[[email protected]  ~]$ find . -name  "*.txt"  -print   //find a. txt file in the current directory and display./test.txt[[ email protected] ~]$ find ~ -name  "*.xml"  -print  //in $  Find the. xml file in home and display the/home/ningning/.gconf/desktop/%gconf.xml/home/ningning/.gconf/desktop/gnome/accessibility/% gconf.xml/home/ningning/.gconf/desktop/gnome/accessibility/keyboard/%gconf.xml/home/ningning/.gconf/desktop/ gnome/%gconf.xml/home/ningning/.gconf/apps/nautilus/%gconf.xml   [[email protected] ~ ]$ find -name  "[a-z]*"  -print  //find a file that begins with a capital letter./downloads./.gconf/apps/ Gnome-terminal/profiles/default./templates./documents./music./pictures./public./videos./desktop[[email protected] ~]$ find -name   "p*"  -print  //find files that begin with a capital letter P./pictures./public[[email protected] ~]$ find  -name  "*s"  -print  //find files ending in lowercase s./.xsession-errors./.gvfs./.gnome2/keyrings./. Gnome2/panel2.d/default/launchers./.gnome2/nautilus-scripts./.dbus./.dbus/session-bus./.gnote/addins./.mozilla /plugins./.mozilla/extensions./downloads./.gtk-bookmarks./.local/share/applications./.local/share/. Converted-launchers./.nautilus./.gconf/apps./templates./documents./pictures./videos[[email protected]  ~]$ find -name  "[a-z]*"  -print //find a file that starts with a lowercase letter./.gnome2/keyrings./.gnome2/ Keyrings/login.keyring./.dbus/session-bus./.dbus/session-bus/dcd26acd87eabb5cc6f2133500000028-0./.gnote/addins ./.mozilla/plugins./.mozilla/extensions./.gnupg/pubring.gpg./.cache/ Event-sound-cache.tdb.dcd26acd87eabb5cc6f2133500000028.i386-redhat-linux-gnu./.pulse/dcd26acd87eabb5cc6f2133500000028-card-database.tdb./name./.gconf/desktop./.gconf/desktop/gnome./.gconf/ Desktop/gnome/accessibility

-perm   Find files according to their permissions

[[email protected] ~]$ find . -perm 755 -print  //Find Permissions 755 files. Gnome2./.gnome2/nautilus-scripts./.fontconfig./.mozilla./.mozilla/plugins./.mozilla/extensions./downloads./. cache./.local./.local/share./.local/share/applications./.nautilus./.config./.config/gnome-session./.config/ Gnome-session/saved-session./.config/gnome-disk-utility./.config/gnome-disk-utility/ata-smart-ignore./ templates./documents./music./pictures./public./videos./desktop//Note the usage of OK and exec [[email protected] ~]$  find -perm -007 -ok -l{} \;  //   #查所有用户都可读写执行的文件同-perm  777< -l{} ... ./.pulse/dcd26acd87eabb5cc6f2133500000028-runtime > ?  yfind:  '-l./.pulse/dcd26acd87eabb5cc6f2133500000028-runtime ': no such file or  Directory[[email protected] ~]$ find -perm -007 -exec -l{} \;find:   '-l./.pulse/dcd26acd87eabb5cc6f2133500000028-runtime ':  no such file or directory 

-user Find files According to the owner of the file

[Email protected] ~]$ Find/-user ningning/proc/14301/task/14301/cwd/proc/14301/task/14301/root/proc/14301/task/ 14301/exe/proc/14301/task/14301/mounts/proc/14301/task/14301/mountinfo/proc/14301/task/14301/clear_refs/proc/ 14301/task/14301/smaps/proc/14301/task/14301/pagemap/proc/14301/task/14301/attr/proc/14301/task/14301/attr/ current/proc/14301/task/14301/attr/prev/proc/14301/task/14301/attr/exec/proc/14301/task/14301/attr/fscreate/ proc/14301/task/14301/attr/keycreate/proc/14301/task/14301/attr/sockcreate/proc/14301/task/14301/wchan/proc/ 14301/task/14301/stack/proc/14301/task/14301

-group Find files according to the group to which the files belong

Find: '/PROC/27825/FD/5 ': No such file or directory/proc/27825/fdinfo/proc/27825/fdinfo/0/proc/27825/fdinfo/1/proc/ 27825/fdinfo/2/proc/27825/fdinfo/3/proc/27825/fdinfo/4find: '/PROC/27825/FDINFO/5 ': No such file or directory/proc/ 27825/ns/proc/27825/ns/net/proc/27825/ns/uts/proc/27825/ns/ipc/proc/27825/ns/mnt/proc/27825/ns/pid/proc/27825/ Net/proc/27825/environ/proc/27825/auxv

Find/home-nouser lists files or directories in/home that are not local users
Find/home-nogroup lists files or directories in/home that are not part of a local group

Find/home-used-2 lists files or directories that have been accessed within 2nd after the file or directory has been altered
Find/home-user CNSCN lists files or directories in the/home directory that belong to the user Cnscn

Find/-nouser files that belong to obsolete users in the system

[[email protected] ~]$ Find/-nouserfind: '/proc/1356/fd ': Permission deniedfind: '/proc/1356/fdinfo ': Permission denied Find: '/proc/1356/ns ': Permission deniedfind: '/proc/1357/task/1357/fd ': Permission deniedfind: '/proc/1357/task/1357 /fdinfo ': Permission deniedfind: '/proc/1357/task/1357/ns ': Permission deniedfind: '/proc/1357/fd ': Permission Deniedfind: '/proc/1357/fdinfo ': Permission deniedfind: '/proc/1357/ns ': Permission deniedfind: '/proc/1382/task/1382 /FD ': Permission denied

-type finding a file of a type

B-Block device files

Catalog D

C-Character device files

P Pipeline File

L Link Character file

F Common Files

[[Email protected] ~]$ find -type d -print]. /.gvfs./.gnome2./.gnome2/keyrings./.gnome2/panel2.d./.gnome2/panel2.d/default./.gnome2/panel2.d/default/ Launchers./.gnome2/nautilus-scripts./.dbus./.dbus/session-bus./.gnote./.gnote/addins./.ssh./.fontconfig./. mozilla./.mozilla/plugins./.mozilla/extensions./downloads./.gnupg./.cache[[email protected] ~]$  find -type f -exec -l{} \;   //See all common Files under directory find:  '-L./.DMRC ' : no such file or directoryfind:  '-l./.xsession-errors ': No such  file or directoryfind:  '-l./.gnome2/keyrings/login.keyring ': no such file  or directoryfind:  '-l./.dbus/session-bus/dcd26acd87eabb5cc6f2133500000028-0 ':  No such  file or directoryfind:  '-l./.gnote/36595867-4cc7-4b1f-b298-b25e9c2080ac.note ':  no  such file or directoryfind:  '-L./.GNOTE/9D4D7c5c-d46e-42eb-8d7f-ed5921568770.note ': no such file or directoryfind:  '-l./. Bash_profile ': no such file or directoryfind:  '-l./.fontconfig/ 3830d5c3ddfd5cd38a049b759396e72e-le32d4.cache-3 ':  no such file or directoryfind:   '-L./.BASHRC ': no such file or directoryfind:  '-l./.pulse-cookie ':  No  such file or directory

-size N:[c]   Find files with a file length of n blocks, with a C-time representation of the file in bytes.

[[email protected] ~]$ find . -size 1000c -print  //Find Files of length 1000c [[email protected] ~]$ find . -size +1000c -print    // Look for files longer than 1000c. /.xsession-errors./.gvfs./.gnome2./.gnome2/keyrings./.gnome2/panel2.d./.gnome2/panel2.d/default./.gnome2/ panel2.d/default/launchers./.gnome2/nautilus-scripts./.dbus./.dbus/session-bus./.gnote./.gnote/ 36595867-4cc7-4b1f-b298-b25e9c2080ac.note./.gnote/addins./.gnote/9d4d7c5c-d46e-42eb-8d7f-ed5921568770.note./. Ssh./.fontconfig./.fontconfig/3830d5c3ddfd5cd38a049b759396e72e-le32d4.cache-3./.mozilla./.mozilla/plugins./. Mozilla/extensions./downloads./.gnupg[[email protected] ~]$ find . -size +10  -print   //Check length expires 10 blocks of files (1 blocks = 512 bytes)./.gnupg/gpg.conf./.cache/ event-sound-cache.tdb.dcd26acd87eabb5cc6f2133500000028.i386-redhat-linux-gnu./.pulse/ Dcd26acd87eabb5cc6f2133500000028-device-volumes.tdb./.pulse/dcd26acd87eabb5cc6f2133500000028-stream-volumes.tdb./.local/share/gvfs-metadata/home-6751745f.log./.gconfd/saved_state./. Gstreamer-0.10/registry.i686.bin./desktop/gnome-terminal.desktop

Find a file with a file size of 5556 bytes

[[email protected] ~]$ find/ningning-size-5557c-size +5555c-exec ls-ld{} \;

Use of common find 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.