Common Linux commands (3) -- File search commands

Source: Internet
Author: User
Common Linux commands (3) -- File search command 1. command name: whichwww.2cto.com command path:/usr/bin/which execution permission: all users function description: display the directory syntax of the system command: which [command name] [root @ localhost... common Linux commands (3) -- File search command 1. command name: which www.2cto.com command path:/usr/bin/which execution permission: all users function description: display the directory syntax of the system command: which [command name] [root @ localhost ~] # Which ls alias ls = 'ls -- color = Auto'/bin/ls [root @ localhost ~] #2. command name: find execution permission: all users function description: find a file or directory syntax: find [search path] [search keyword] 1) -name: search by name * matching any character? Match a single character www.2cto.com. find the file init [root @ localhost ~] in the/etc directory by name. # Find/etc-name init/etc/webmin/init/etc/kdump-adv-conf/kdump_initscripts/init/etc/sysconfig/init [root @ localhost ~] # Use the * wildcard to search for files starting with init [root @ localhost ~] # Find/etc-name init */etc/selinux/targeted/contexts/initrc_context/etc/inittab/etc/webmin/init/etc/kdump-adv -conf/kdump_initscripts/init/etc/init/init-system-dbus.conf/etc/rc. d/init. d/etc/sysconfig/init/etc/sysconfig/network-scripts/init. ipv6-global/etc/init. d [root @ localhost ~] # Use? Wildcard search for files starting with init and followed by three characters [root @ localhost ~] # Find/etc-name init ??? /Etc/inittab/etc/webmin/inittab [root @ localhost ~] #2)-size: search for data blocks based on the file size) in the unit of 512 bytes = 2048 kB + less than-or equal to the direct and numerical values in the/etc directory to find files larger than 1 MB 1 MB = kb = data blocks) [root @ localhost ~] # Find/etc-size + 2048/etc/selinux/targeted/policy/policy.24/etc/selinux/targeted/modules/active/policy. kern/etc/gconf. xml. defaults/% gconf-tree.xml [root @ localhost ~] #3)-The user searches for the files whose owner is luxh in the/home directory based on the file owner [root @ localhost ~] # Find/home-user luxh 4) query by time (in the unit of days): ctime, atime, mtime (in minutes ): cmin, amin, and mmin c --> change indicates that the attributes of the file have been modified. for example, the owner, group, and permission of the file have been changed. a --> access, indicates that the file has been accessed by m --> modify modification, indicates the file content has been modified-indicates how long it will take + indicates how long it will take to search for the files and directories that have been modified in the/etc directory within one day [root @ localhost ~] # Find/etc-ctime-1/etc/resolv. conf/etc/mtab/etc/avahi/etc/localtime [root @ localhost ~] # Search for files modified within two hours in the/etc directory (120 minutes in two hours) [root @ localhost ~] # Find/etc-mmin-120/etc/resolv. conf/etc/mtab [root @ localhost ~] #5)-type searches for f second-level files based on the file type, l soft-link files, d directory searches for directory files under/etc directory [root @ localhost ~] # Find/etc-type d 6) connector: 6.1)-a and logic and, -o or logic or search for files larger than 80 MB and smaller than MB in the/etc directory [root @ localhost ~] # Find/etc-size + 163840-a-size-204800 6.2) find... -exec command {}\; or find... -OK command {}\;-OK will have the result \ escape character of the query {} find process, so that the symbols and commands use their own meaning. result, indicates that the statement ends. search for the inittab file in the/etc directory and display its details. [root @ localhost ~] # Find/etc-name inittab-exec ls-l {}\;-rw-r --. 1 root 884 May 5 2012/etc/inittabtotal 4-rw -------. 1 root bin 42 May 16 2012 config [root @ localhost ~] # Find and delete testfile [root @ localhost ~] in the/abc Directory # Find/abc-name testfile-exec rm-rf {}\; find and delete a.txt under the/abcdirectory. if you use-OK, the system will prompt [root @ localhost ~] # Find/abc-name a.txt-OK rm {}\; <rm.../abc/a.txt>? Y. find the directory files starting with init * in the/etc directory and display their information in detail. [root @ localhost ~] # Find/etc-name init *-a-type f-exec ls-l {}\;-rw-r --. 1 root 30 Dec 7 2011/etc/selinux/targeted/contexts/initrc_context-rw-r -- r --. 1 root 884 May 5 2012/etc/inittab-rwxr-xr-x. 1 root 4781 Oct 29 2009/etc/kdump-adv-conf/kdump_initscripts/init-rw-r --. 1 root 130 Jul 18 2011/etc/init/init-system-dbus.conf-rw-r -- r --. 1 root 1154 Dec 8 2011/etc/sysconfig/init-r Wxr-xr-x. 1 root 4623 Oct 7 2011/etc/sysconfig/network-scripts/init. ipv6-global [root @ localhost ~] #7)-inum searches for the I node of the ls-I display file based on the file I node [root @ localhost ~] # Ls-I/abc 5355 issue. hard 129390 issue. soft 130438 prem [root @ localhost ~] # Find/abc-inum 5355/abc/issue. hard [root @ localhost ~] # Sometimes someone else may have created some files with strange names and cannot delete them using rm [root @ localhost ~] # Ls-l/abctotal 4-rw-r -- r --. 1 root 0 Nov 20 06:09 a B-rw-r --. 3 root 0 Nov 15 issue. hardlrwxrwxrwx. 1 root 10 Nov 15 issue. soft->/etc/issuedrwxr-xr-x. 2 root 4096 Nov 15 05:36 prem [root @ localhost ~] # Rm a brm: cannot remove 'A': No such file or directoryrm: cannot remove 'B': No such file or directory [root @ localhost ~] # You can delete [root @ localhost ~] based on the I node of the file. # Ls-I/abc a B 5355 issue. hard 129390 issue. soft 130438 prem [root @ localhost ~] # Find/abc-inum 129330-exec rm {}\; [root @ localhost ~] # Ls-I/abc issue. hard 129390 issue. soft 130438 prem [root @ localhost ~] #3. command name: locate execution permission: all users function description: search for files or directories syntax: locate [search keyword] [root @ localhost ~] # Locate inittab locate is found in a file database regularly updated by the system, which is faster. The system automatically calls updatedb to regularly update the directory file database 4. command name: updatedb execution permission: root function description: create the database syntax of the entire system directory File: updatedb 5. command name: grep execution permission: therefore, user function description: Searches for strings matching rows in the file and outputs the syntax: grep [specified string] [source file] Searches for tftp-matched rows in the/etc/services file [root @ localhost ~] # Grep tftp/etc/servicestftp 69/tcptftp 69/udptftp-mcast 1758/tcptftp-mcast 1758/udpmtftp 1759/udp spss-lmsubntbcst_tftp 247/tcp # protocol 247/udp # SUBNTBCST_TFTPetftp 1818/tcp # Enhanced Trivial File Transfer Protocoletftp 1818/udp # Enhanced Trivial File Transfer Protocoltftps 3713/tcp # TFTP over TLStftps 3713/udp # TFTP over TLS [root @ localhost ~] #

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.