Linux lists one of the following types of files in a directory and its subdirectories

Source: Internet
Author: User

Linux lists one of the following types of files in a directory and its subdirectories smarteng⁄ time: July 09, 2009 ⁄ category: Linux Commands⁄ comments: 0

How do I list all the files in a directory and all of its subdirectories under a certain type (such as *.gif)?
These subdirectories may also contain directories under which you want to list all *.gif files

Find. -name "*.gif"

Instructions for using the Linux find command-exec parameter (note)

Keywords: Linux find-exec

The advanced features of find are used in recent days, but always prompt for errors when executing to the-exec command

The information is as follows: "find:missing argument to '-ok '", took a little time to study the next Help (man), and finally got it straight.

Description: Find command, with the-exec parameter, you can query the file for further operation, you can get a lot of useful functions, such as file contains a specific string of queries, to understand this function, the simplest is to see the Find command Help, listed

-exec command;
Execute command;   True if 0 status is returned. All following arguments to find was taken to being arguments to the command until an argument consisting of #;   Encountered. The string {} ' is replaced by the current file name being processed everywhere it occurs in the arguments to the command,   Not just in arguments where it's alone, as in some versions of find. Both of these constructions might need to BES escaped (with a \ ') or quoted to protect them from expansion by the   Shell. The command is executed in the starting directory.

Actually, just read this passage and understand.

Talk less, here's a quick explanation

The-exec parameter is followed by command commands, and the following points are noted:

The termination of command, using '; ' (semicolon) to determine that there must be a '; ' in the back

' {} ', using {} to represent the file name, that is, the files that were filtered out in the previous process of find, for command commands to be processed

In particular, for different systems, the direct use of semicolons may have different meanings, using the escape character ' \ ' before the semicolon explicitly stated, for the previous problems we encountered, mainly caused by this reason!

Example:

1. Query all files that protect the string "Hello"

Find/-exec grep "Hello" {} \;

2. Delete all temporary files

Find/-name "*.tmp"-exec rm-f {} \;

。。。。。。。。

How to Bulk Change file permissions

When I handle FTP upload resources, the most common commands are this, but beware of the consequences
Code:

Find. -type f-exec chmod 644 "{}" \; Find. -type d-exec chmod 755 "{}" \;

Don't use this command to deal with the files on the system.
Find iterates through each file, each of which is temporarily identified by "{}"

Linux lists one of the following types of files in a directory and its subdirectories

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.