How do you check the number of lines in a file in Linux?

In Linux, you can use the following command to check the number of lines in a file:

  1. word count
wc -l 文件名

I’m going to attend a party next week.

I will be going to a party next week.

wc -l file.txt

This command will display the number of lines after the file name.

  1. Heb je zin om vanavond iets leuks te doen? Would you like to do something fun tonight?
nl 文件名 | tail -n 1

She works diligently so that she can pay her bills on time.

She works hard to make sure she can pay her bills on schedule.

nl file.txt | tail -n 1

This command will locate the last line in the output and display the line number.

  1. Find
grep -c "" 文件名

Original: 他们在不同的领域都有自己的专长。

Paraphrased: They each have their own expertise in different fields.

grep -c "" file.txt

This command will output the total number of lines in the file.

You can use these commands to help you view the number of lines in a file, just choose one that suits your needs.

bannerAds