How to check how many lines a file has in Linux

青灯夜游
Release: 2021-11-29 10:14:25
Original
16774 people have browsed it

In Linux, you can use the wc command to check how many lines a file has. The function of this command is to count the number of bytes, words, and lines in the specified file, and display and output the statistical results. The syntax "wc -l filename".

How to check how many lines a file has in Linux

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

In Linux, you can use the wc command to see how many lines a file has.

The main function of the wc (Word Count) command in the Linux system is to count the number of bytes, words, and lines in the specified file, and to display and output the statistical results.

This command counts the number of bytes, words, and lines in the specified file. If no filename is given, then standard input is read. wc also gives the total count of the specified files.

Syntax:

wc [-clw][--help][--version][filename...]
Copy after login

Parameters:

  • -c or --bytes or --chars Display only the number of Bytes.

  • -l or --lines displays the number of lines.

  • -w or --words displays only the number of words.

  • --help Online help.

  • --version Display version information.

Usage is as follows:

$ wc 1.txt         # 统计文件的行数、单词数、字符数
 2  4 24 1.txt

 $ wc -l 1.txt      # 统计文件的行数
2 1.txt

$ wc -w 1.txt      # 统计文件的单词数
4 1.txt

$ wc -m 1.txt      # 统计文件的字符数
24 1.txt

$ wc -c 1.txt      # 统计文件的字节数
24 1.txt

$ wc -L 1.txt      # 统计文件中最长行的长度,也就是最长的那一行有多少个字符
11 1.txt

$ ls /etc | wc -l  # 统计指定目录下的文件或目录个数
222
Copy after login

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to check how many lines a file has in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template