Linux trivial record-the number of lines in the statistical source code

Source: Internet
Author: User

WC commands in Linux are statistics.CodeThe usage of the number of rows is as follows:

 
Usage: WC [Option]... [file]...
Or: WC [Option]... -- files0-From= F
Output the number of lines, word counts, and number of cells of each specified file.
If there is more than one file, the total data of all related data will continue to be provided. If no
File, or the file is"-", The data is read from the standard input.
-C, -- bytes output Byte Count statistics
-M, -- chars output character count statistics
-L, -- lines output row count
-- Files0-From= The name of the specified file to be read by NUL. If the file is
Specified"-"Then, read the file name from the standard input.
-L, -- Max-line-length: display the length of the longest row
-W, -- words display word count
-- Help: displays the help information and exits.
-- Version: displays the version information and exits.

WC-L *. C *. h shows the detailed information about the number of lines of all C and H files in the current directory. Very good

If recursion is required, it can be used together with other commands.

Current Directory and subdirectory:
Find.-Name *. c | xargs WC-l
Find.-Name *. cpp | xargs WC-l
Find.-Name *. H | xargs WC-l

Think of it all at once, maybe you can simply use the redirection Technology

Find-name "*. C ">/tmp/file. list; find-name "*. H ">/tmp/file. list; CAT/tmp/file. list | xargs WC-L; RM/tmp/file. list

Or this is more convenient:

 
WC-l 'Find./-name "*. c"; find-name "*. H" '| tail-N1

2. count the number of files

Find.-Name *. c | WC-l

3. count the number of lines of code (filter empty lines)

Find.-Name *. c | xargs cat | grep-V ^ $ | WC-l

$ Find -- Help
Usage: find [-H] [-L] [-p] [-olevel] [-D help | tree | search | stat | rates | opt | exec] [path...] [expression]

The default path is the current directory. The default expression is-print.
An expression may consist of the following components: operator, option, test expression, and action:

Operator (descending priority;-and is used by default when no indicator is specified ):
(Expr )! Expr-not expr expr1-A expr2 expr1-And expr2
Expr1-O expr2 expr1-or expr2 expr1, expr2

Location Option (always true):-daystart-Follow-regextype

Common options (always true, specified before other expressions ):
-Depth -- Help-maxdepth levels-mindepth levels-mount-noleaf
-- Version-xdev-ignore_readdir_race-noignore_readdir_race

Test (N can be + N or-N or N):-Amin N-anewer file-atime N-Cmin
-Cnewer file-ctime N-empty- False -Fstype type-gid N-group name
-Ilname match mode-INAME match mode-inum N-ipath match mode-iregex match Mode
-Links N-lname matching mode-mmin N-mtime N-name matching mode-newer File
-Nouser-nogroup-Path Matching mode-Perm [+-] Access Mode-RegEx matching mode
-Readable-writable-executable
-Wholename pattern-size N [bcwkmg]- True -Type [bcdpflsd]-UID n
-Used n-user name-xtype [bcdpfls]

Action:-delete-print0-printf format-fprintf file format-print
-Fprint0 file-fprint file-ls-FLS file-prune-quit
-Exec command;-exec command {}+-OK command;
-Execdir command;-execdir command {} +-okdir command;

HTTP: // savannah.gnu.org/reports errors and tracks the fixing process. If you cannot browse the Web page, email to .

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.