Linux learning Note 3 file search command

Source: Internet
Author: User
Linux Study Notes 3 file search command links: Linux Study Notes 1 file Operation Commands http://www.2cto.com/os/201211/169196.html Linux study Note 2 permission management commands http://www.2cto.com/os/201211/169485.html 1. which, w... Linux study Note 3 file search command link: Linux study Note 1 file Operation Command http://www.2cto.com/os/201211/169196.html Linux study Note 2 permission management commands http://www.2cto.com/os/201211/169485.html 1. which and whereis directly locate the absolute path of the command, only for commands. whereis provides command help information www.2cto.com [root @ CentOS-Test data] # whereis ls: /bin/ls/usr/share/man/man1/ls.1.gz/usr/share/man/man1p/ls.1p.gz which provides command alias [root @ CentOS-Test data] # which ls alias ls = 'ls -- color = Auto' 2. use this command to find a file or directory and specify the search path first, then set the search method-name to search for all matching init [root @ CentOS-Test data] # find/etc-name init/etc/sysconfig/init/etc/init based on the file name /etc/kdump-adv- Conf/kdump_initscripts/init fuzzy query init *: match any character [root @ CentOS-Test data] # find/etc-name init */etc/inittab/etc/rc. d/init. d/etc/init. d/etc/sysconfig/network-scripts/init. ipv6-global/etc/sysconfig/init/etc/init/init-system-dbus.conf/etc/selinux/targeted/contexts/initrc_context/etc/kdump-adv-conf/kdump_initscripts/init?: Match a single character [root @ CentOS-Test data] # find/etc-name init ?? /Etc/rc. d/init. d/etc/init. d-size: based on the file size, the unit is block, 1 M = 1024 k * 2 = 2048 block is greater: + [root @ CentOS-Test data] # find-size + 2048. /cc.txt smaller than:-[root @ CentOS-Test data] # find-size-2048. /cc.txt-user: searches by the file owner. for example, after a user is deleted, some files created by the user will still exist. if the user is deleted, you need to use this parameter [root @ CentOS-Test data] # find-user test to search by time, which can be divided into two groups: c-change (change ), indicates that the file attributes have been modified, such as the file owner and permissions. you can use ll to view a-access ), indicates that the file has been viewed and accessed by m-modify, indicating that the file content has been modified. For example, add a row to the file.-: Plus +: Over 1, Day: ctime, atime, mtime 2, minute: cmin, amin, and mmin. for example, you can find the [root @ CentOS-Test data] # find/etc-mmin-120 modified file content in the/etc/directory within two hours. -: equivalent to and, it can be understood as logic and-o: equivalent to or, it can be understood as logic or using the file type logic and parameters as init * and binary [root @ CentOS-Test data] # find/etc-name init *- the a-type f file is of the init * type and is a link file [root @ CentOS-Test data] # find/etc-name init *-a-type l the file type is init * the Directory [root @ CentOS-Test data] # find /Etc-name init *-a-type d indicates that the file type logic or parameter is init * and the file type is binary [root @ CentOS-Test data] # find/ etc-name init ?? -O-type f: the file type is init * and it is a link file [root @ CentOS-Test data] # find/etc-name init? -O-type l the file type is init * and is the directory [root @ CentOS-Test data] # find/etc-name init ?? -O-type d: execute the exec-exec command {}\. this parameter is used with the find command to execute exec (execution) on the result of the find query) {}: indicates the result of the find query; \: indicates the escape character so that the symbols and commands use their own meanings. for example, when you use rm to delete a file, if you do not add a parameter, you will be prompted whether to confirm. The original intention of this command is rm = rm-I; you can use which rm to see the alias, therefore, when deleting a file, you are not prompted to use [root @ CentOS-Test data] # \ rm file name;: indicates that a command ends, for example: search for the inittab file under/etc and Display [root @ CentOS-Test data] # find/etc-name inittab-exec ls-l {}\; search for files containing xx in/data and delete them. do not confirm [root @ CentOS-Test data] # find. /-name xx * -Exec rm-f {}\; [root @ CentOS-Test data] # find. /-name baks-exec rm-r {}\; delete directory-OK: ask for confirmation. it is useful for executing the delete action [root @ CentOS-Test data] # find. /-name bak-OK ls {}\; <ls .... /bak>? Yes-inum parameter: delete a file with special characters according to the inode node of the file, for example, delete-abc 'a B, you can use the I node of the file to delete the I node that first uses ls-I to find the file, then run the find command to delete [root @ CentOS-Test data] # mkdir ---abc [root @ CentOS-Test data] # ls-abc bak [root @ CentOS-Test data] # ls-I 13-abc 12 bak [root @ CentOS-Test data] # find. /-inum 13-exec rm {} \; 3. search for files or directories in the locate file name or directory name to list all files related to the file name, the locate command is found in the regular file database (updatedb, the newly created updatedb file cannot be found when the file database is not updated. the updatedb file is automatically updated on a regular basis. 4. grep searches for strings matching rows in the file and outputs the syntax: grep [specify a string] [source file] grep 'lhc '/data/xx.txt 5. use find + grep + xargs in combination to find all txt files in the current directory, find the 'SS' file in the txt file and list it with [root @ CentOS-Test data] # find. /-name "*. txt "| xargs grep 'SS'
Related Article

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.