Using Linux's wc command combined with other commands to calculate rows and other information. Count with wc under Linux. Returns the number of lines, words, bytes, etc. of the file.
See an example: wc wc1.txt3 5 16 wc1.txt The output information is: line number Words Bytes File name. More specific, a single statistic. Wc -m filename: displays the number of characters in a file wc -l filename: displays the number of lines in a file wc -L filename: displays the length of the longest line in a file wc -w filename: the number of words in a file needs to be noted : Looks like wc statistics is determined by line breaks. That is to say, the last line should have a newline, and the number of lines in the last wc is correct, otherwise there will be one less line. To illustrate this problem, look at a perl test: perl -e 'print "a"'|
Wc0 1 1perl -e 'print "a\ "'|
Wc1 1 2 In the above example, the print command prints a. If there is no line break \ , then the line does not exist. There are the following points: 1: A Chinese character occupies three bytes (unauthenticated, personally thinks it is two bytes), an invisible character such as a carriage return also occupies a byte 2: the end of a line if not returned The car character is not a line, that is, if there is no line break at the end of the last line of a file, the number of lines counted by the wc command will be one less than the actual number of lines. The actual number of lines is the number of lines you see. In fact, there is no carriage return, it really can't be counted as a line (Note: if it is in an existing text, the default is that all lines have an invisible carriage return) 3: The so-called one word is a continuous character , that is, a continuous letter or Chinese character that is not divided by a null character is counted as a word. For example, the following is a text called abc.txt, which is opened after using vi: (For the sake of detail, we use the arrow ┘ to indicate the carriage return. Actually there is no) You are nice.Right??OK.~~~You are nice.┘Right??┘┘┘OK.┘~~~ Then:wc abc.txt6 5 28 abc.txt ie 6 lines, 5 words, 28 characters. Let's count it. There are 6 lines of invisible carriage returns; there are 5 consecutive letters that are not separated by null characters, namely You, are, nice., Right??, OK. Bytes (or characters) contain carriage returns. A total of 28. For example: example1: How to count the number of files in a directory and the total number of lines of code under linux command to know the total number of files with the specified suffix name: find . -name "*.cpp" |
Wc -l knows the total number of lines of code in a directory and the number of individual file lines: find . -name "*.h" |
Xargs wc -l
example2: Number of files in the linux statistics folder
The first method: ls -l|
Grep “^-”|
Wc -l
ls -l Long list output file information in this directory (note the files here, different from normal files, may be directories, links, device files, etc.). If ls -lR|
Grep “^-”|
Wc-l can be counted together with files in subdirectories.
grep ^- Here, the long list output information is filtered, and only the general file is retained. If only the directory is reserved, ^d
wc -l counts the number of rows of the output information because it has been filtered. Only the general file is left, so the statistical result is the number of lines of general file information, and since one line of information corresponds to one file, it is the number of files.
The second method: find ./-type f|
Wc -l
Because the default find will go to the subdirectory search, if you only want to find the file in the current directory, use find ./-maxdepth 1 -type f|
Wc -l can be.
It should be noted that the second method will be much faster than the first method, especially when counting subdirectories. Example3: Want to know how many users are logged into the system? Who |
Wc -l
Overview This article describes how to transfer files between a Linux host and a Windows host. Beca
STM32F103VCT6 comes with two 12-bit DAC, DAC conversion speed has not been found, some people say th
for Windows 7 computers Microsoft will allow its computer OEMs and their system co-developers to d
Now let us use the two digital tubes on the experiment board to do a cycle to display the 00~99 numb
Graphic mode and text mode switch between Linux installations
Remote Warehouse Usage Tutorial
Modify system time under Linux
Personal Notes on Linux Virtual Memory Management
Linux Environment Programming - Process Communication
Linux station group rsync synchronization basic tutorial
Linux available disk capacity adjustment reserved space
Installing Virtualbox Virtual XP on Ubuntu System
Win7 system 64-bit flagship version batch modification photo name
How to install windows xp to easy pc from u disk detailed process
Reject IE8 to access the Https website pop-up tips
How to set Win8 to open window in new tab
Win10 March update fixes Edge browser PDF security vulnerability
How to delete the invalid icon of the Win7 notification area
Use Win7 network diagnostic tool to solve wireless network connection problems in six easy steps