Count the number of files suffixed with. CC,. C, and. h.

Source: Internet
Author: User
Tags control characters

When developing a project, you may want to know how many files with the suffix. CC,. C, and. h are in the source code file. The following describes how to count the number of files suffixed with. CC,. C, and. h in Linux.

Taking the python 3 source code as an example, the total number of Python 3 source code files is as follows:

I am studying python3 during this time, so I will take it as an example. Feeling: python3 and python2 have changed a lot! If you are interested, you can study the checkout code in the code library. The process is as follows: (python3 uses Git to manage the code)

  • Mkdir py3k. Git
  • CD py3k. Git
  • Git init
  • Git SVN init SVN + SSH: // pythondev@svn.python.org/Python/branches/py3k
  • Git remote add Git-SVN git: // code.python.org/python/branches/py3k
  • GitHub config remote. git-svn.fetch refs/heads/master: refs/remotes/Git-SVN
  • Git fetch Git-SVN
  • Git pull Git-SVN master
Method 1

Count the number of. CC files and. c/. H files respectively, and add them together.

 
1 find . -name "*.cc" | wc -l ;find . -name  "*.[c|h]"|wc -l

 

Although we can get the correct result, it looks ugly.

Method 2
1 find . \( -name "*.cc" -or -name "*.c" -or -name "*.h" \) |wc -l

Use the-or command to connect multiple expressions. Note that all-name expressions are enclosed by parentheses () and must be escaped! The result is as follows:

Method 3
1 find . -iregex ".*\.\(cc\|h\|c\)$" |wc -l

Use a regular expression, but be careful to escape it. The result is as follows:

Meanings of the symbol with common Regular Expressions:

    \Mark the next character as a special character, a literal character, a back reference, or an octal escape character.
    ^Matches the start position of the input string. If the multiline attribute of the Regexp object is set, ^ matches the position after '\ n' or' \ R.
    $Matches the end position of the input string. If the multiline attribute of the Regexp object is set, $ also matches the position before '\ n' or' \ R.
    *Matches the previous subexpression zero or multiple times.
    +Match the previous subexpression once or multiple times. + Is equivalent to {1 ,}.
    ?Match the previous subexpression zero or one time .? It is equivalent to {0, 1 }.
    {N}N is a non-negative integer that matches the specified n times.
    {N ,}N is a non-negative integer and must be matched at least N times.
    {N, m}Both m and n are non-negative integers, where n <= m. Match at least N times and at most m times. There must be no space between a comma and two numbers.
    ?When this character is followed by any other delimiter (*, + ,?, The matching mode after {n}, {n ,}, {n, m}) is not greedy. The non-Greedy mode matches as few searched strings as possible, while the default greedy mode matches as many searched strings as possible.
    .Match any single character except "\ n. To match any character including '\ n', use a pattern like' [. \ n.
    (Pattern)Match pattern and obtain this match.
    (? : Pattern)Matches pattern but does not get the matching result. That is to say, this is a non-get match and is not stored for future use.
    (? = Pattern)Forward pre-query: matches the search string at the beginning of any string that matches the pattern. This is a non-get match, that is, the match does not need to be obtained for future use.
    (?! Pattern)Negative pre-query, and(? = Pattern)Opposite Effect
    X | yMatch X or Y.
    [Xyz]Character Set combination.
    [^ XYZ]Negative value character set combination.
    [A-Z]Character range, matching any character in the specified range.
    [^ A-Z]The negative value range matches any character that is not within the specified range.
    \ BMatch A Word boundary, that is, the position between a word and a space.
    \ BMatch non-word boundary.
    \ CXMatch the control characters specified by X.
    \ DMatch a numeric character. It is equivalent to [0-9].
    \ DMatch a non-numeric character. It is equivalent to [^ 0-9].
    \ FMatch a form feed. It is equivalent to \ x0c and \ Cl.
    \ NMatch A linefeed. It is equivalent to \ x0a and \ CJ.
    \ RMatch a carriage return. It is equivalent to \ x0d and \ cm.
    \ SMatches any blank characters, including spaces, tabs, and page breaks. It is equivalent to [\ f \ n \ r \ t \ v].
    \ SMatch any non-blank characters. It is equivalent to [^ \ f \ n \ r \ t \ v].
    \ TMatch a tab. It is equivalent to \ x09 and \ CI.
    \ VMatch a vertical tab. It is equivalent to \ x0b and \ ck.
    \ WMatch any word characters that contain underscores. It is equivalent to '[A-Za-z0-9 _]'.
    \ WMatch any non-word characters. It is equivalent to '[^ A-Za-z0-9 _]'.
    \ XNMatch n, where N is the hexadecimal escape value. The hexadecimal escape value must be determined by the length of two numbers.
    \ NumMatches num, where num is a positive integer. References to the obtained matching.
    \ NIdentifies an octal escape value or a backward reference. If at least N subexpressions are obtained before \ n, n is a backward reference. Otherwise, if n is an octal digit (0-7), n is an octal escape value.
    \ NmIdentifies an octal escape value or a backward reference. If there are at least is preceded by at least nm obtained subexpressions before \ nm, then nm is backward reference. If at least N records are obtained before \ nm, n is a backward reference followed by text M. If none of the preceding conditions are met, if n and m are Octal numbers (0-7), \ nm matches the octal escape value nm.
    \ NMLIf n is an octal number (0-3) and M and l are Octal numbers (0-7), the octal escape value NML is matched.
    \ UNMatch n, where n is a Unicode character represented by four hexadecimal numbers.

    From proficient Regular Expressions

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.