Shell to find query file operation instance

Source: Internet
Author: User

Example 1

Typical operation, traversing all JS in the directory and using Yuicompressor compression

The code is as follows Copy Code

For i in ' Find Asset/v2-name ' *.js ';
Todo
echo "Compress $i"
Java-jar Tool/yuicompressor.jar--charset=utf8-o $i $i--nomunge
Done

Example 2

Example of execution

Find files and directories in. C under the current directory

The code is as follows Copy Code

Find-name "*.C"


Find only files and directories in the current directory with. C, and subdirectories are not searched.

The code is as follows Copy Code

Find-maxdepth 1-name "*.C"


Find files and piping files of a soft connection in the/home directory and use the LS directive to list their details.

The code is as follows Copy Code

Find/home-type p-o-type L |xargs ls-l


Find which subdirectories are in the/home/mail directory.

The code is as follows Copy Code

Find/home/mail-type D-print


Look for a file with the suffix. SH 1 days ago in the/home/directory.

The code is as follows Copy Code

find/home/-ctime 1-name "*.sh"-exec ls-l {};

Search the entire system for files with hard connections and larger than 880KB, and print them out.

The code is as follows Copy Code

Find/-type F! -links 1-size +880k-exec ls-lh {}; 2>/dev/null


Finds executables with setuid throughout the system.

The code is as follows Copy Code
Find/-perm 4755-print 2>/dev/null|xargs ls-l


Finds executables with setuid throughout the system. Ignores searches for the/bin directory.

The code is as follows Copy Code

Find/-path "/bin"-prune-o-perm 4755-print 2>/dev/null|xargs ls-l


Find files in the/home/directory within 3rd of the change time

The code is as follows Copy Code

Find/home/logs-type f-mtime-3-exec ls-l {};


Look for files in the entire system that have a 755 suffix of. Sh or. php, and avoid the/usr/bin,/bin,/usr/local/bin directories.

The code is as follows Copy Code

Find/-type f-perm 755-a-name "*.php"-o-name "*.sh"-A (-path/bin-o-path/usr/bin-o-path/usr/local/bin)-pru Ne


find a specified size file

Example: Find files with a file size of 2048 (2k) bytes in the current directory

The code is as follows Copy Code

Find./-size 4
Or
Find./-size 2048c
Or
Find./-size 2K


The lookup file above is equal to the specified size, can you query for a file greater than or less than a specified value, the answer is yes, for example:

Look for files larger than 2K, + = greater than

The code is as follows Copy Code
Find./-size +2048c

Look for files less than 2K-represents less than

The code is as follows Copy Code
Find./-size +2048c-type F

Note: The default unit is B, and it represents 512 bytes, so 2 means that 1k,1m is 2048, if you do not want to convert, you can use other units, such as C, K, M and so on.

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.