One step at a day: Linux commands to find files

Source: Internet
Author: User

Linux command to find files

Some files for a long time do not forget the name, only a vague impression, at this time to find the file command is particularly important! Linux provides more powerful lookup commands than Windows.

(This is just a few of the usual, so don't explain it in detail ~ ~ ~)

1. Find

Command format:

Find < Specify directory > < options > < parameters > < specify Actions >

< Specify directory >: usually the default directory

< options >< Parameters >:

-name Search by file name
-iname Search by file name, but not case-sensitive

-user Find files According to the owner of the file: Find/-user Fred//Find files belonging to Fred This user in the system

Use of-a,-o,-not:-A connection two different conditions (two conditions must be met at the same time)

#find/tmp-name "*.sh"-a-user root

-O Connection two different conditions (two conditions to satisfy one)

#find/tmp-name "*.sh"-o-user root

-not on the condition inversion

#find/tmp-not-user Root

-type find a file of a certain type: F normal file D directory

-size N[c] Find files with a file length of n blocks, with C indicating file length in bytes: #find/tmp-size 2M//Find files equal to 2M in/tmp directory

< specify Actions >:

-print//actions by default
-ls//Find and then use LS to display it

Example: Finding a file with a known part of the file name log: Find-name "*log*" (looking in the current directory)

Immediately displays the "config.py" file information on the screen after finding the "config.py" file: Find. -name "config.py"-ls

2. Locate(better than find, faster than find, it searches the database directly)

It is a good idea to update the database before you find it, which is necessary for new files, command: UpdateDB

Search all files starting with SH in the ETC directory: locate/etc/sh

Search for all files starting with M in the user's home directory: Locate ~/m

Search for all files starting with M in the user's home directory, and ignore case: Locate-i ~/m

Find makefile to do the end of the file: Locate-r makefile$

Find files that start with/var/lib/dpkg/info/: Locate-r ^/var/lib/dpkg/info/

La la la la la cheer ~ ~ ~ (today is also a happy to send several ^-^)

One step at a day: Linux commands to find files

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.