Basic Linux commands-(2)

Source: Internet
Author: User

1. General Form of the find command:
Find pathname-options [-print-Exec-OK]
Pathname find command to find the directory path

2. Use the name option:
Find/etc-name "Host *"-print find the file name starting with host in the/etc directory
Find.-Name "[A-Z] *"-print find a file in the current directory with a file name starting with an uppercase letter

3. Use the perm option:
Find.-Perm 755-print: Find Files in the current directory with 755 permission

4. Use the prune option to ignore a directory:
Find/apps-name "/apps/bin"-prune-o-print searches for files in the/apps directory, but does not want to search for files in the/apps/bin directory.

5. Use the user and nouser options:
Find ~ -User Dave-print: In the $ home directory, find the file whose owner is Dave.
Find/home-nouser-print find the files that have been deleted by the owner account in the/Home Directory

6. Use group and nogroup options: The same method is used.

7. Search by change time:
Find/-mtime-5-print: Find the file whose modification time is within 5 days in the root directory
Find/var/adm-mtime + 3-print in the/var/adm directory, find the file whose modification time was earlier than 3 days.

8. Search for new or old files:
Find.-newer age. awk! -Newer belts. awk-exec LS-l {}\; find the files whose change time is earlier than age. awk but earlier than belts. awk.

Assume that the current time is and you want to search for files whose change time is within two hours.
First, you can create such a file: Touch-T 05042140 dstamp
In the current directory, find the file whose modification time is less than two hours: find.-newer dstamp-print.

9. Use the type option:
Find .! -Type D-print: searches for all types of files in the current directory except the directory.
Find/etc-type L-print all symbolic link files under the/etc directory

10. Use the Size Option:
Find.-size + 000000c-print search for files with a length greater than 1 MB in the current directory
Find/home/Apache-size 100c-print in the/home/Apache directory to find a file with a length of exactly 100 bytes

11. Use the depth option:
Find/-name "com. file "-depth-print starts from the root directory of the file system and finds a file named con. file, it will first match all the files and then enter the subdirectory to find

12. Execute the shell command using exec or OK:
The exec option is followed by the command to be executed, followed by a pair of characters {}, a space, a \, and a semicolon.

Find.-Type F-exec LS-l {}\; match all common files in the current directory, and use the LS-l command in the-exec option to list them
Find logs-type F-mtime + 5-exec RM {}\; in the/logs directory, find the files whose change time was earlier than 5 days and delete them

-OK is the safe mode of-Exec
Find. -Name "*. log "-mtime + 5-OK RM {} \; find all file names in the current directory. at the end of the log, change the files whose time is more than five days and delete them, but a prompt will be given before the deletion. Press Y to delete, and press n to not delete

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.