Перейти к содержимому

Bash wc l что это

  • автор:

Sorry, you have been blocked

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.

Cloudflare Ray ID: 7a255054e92077b5 • Your IP: Click to reveal 88.135.219.175 • Performance & security by Cloudflare

Linux wc command

On Unix-like operating systems, the wc command counts the words, newlines, or bytes of each input file, and outputs the result.

This page covers the GNU/Linux version of wc.

Description

wc prints newline, word, and byte counts for each FILE, and a total if more than one FILE is specified. With no FILE, or when FILE is a dash ("—"), wc operates on standard input. (A word is a non-zero-length sequence of characters delimited by white space.)

The options below can select which counts are printed. Counts are always in the following order: newline, word, character, byte, maximum line length.

Syntax

Options

-c, —bytes Print the byte counts.
-m, —chars Print the character counts.
-l, —lines Print the newline counts.
—files0-from=F Read input from the files specified by null-terminated names in file F; if F is "—" then read names from standard input.
-L, —max-line-length Print the length of the longest line.
-w, —words Print the word counts.
—help Display a help message, and exit.
—version Output version information, and exit.

Examples

Displays information about the file myfile.txt. Output resembles the following:

Where 5 is the number of lines, 13 is the number of words, and 57 is the number of characters.

This command returns the number of objects in the current directory. It uses the ls command to produce a single-column (-1) listing of the directory contents, which outputs one line per object; this output is piped to wc, which counts the lines (-l), and returns that number.

Related commands

cksum — Calculate and display a CRC for files.
nl — Number the lines in a file.

6 примеров команд WC для подсчета количества строк, слов и символов в Linux

Команда wc (количество слов) в операционных системах Unix/Linux используется для определения количества символов новой строки, количества слов, байтов и символов в файлах, указанных аргументами файла. Синтаксис команды wc показан ниже.

Ниже приведены параметры и способы использования, предоставляемые командой.

Итак, давайте посмотрим, как мы можем использовать команду «wc» с их немногими доступными аргументами и примерами в этой статье. Мы использовали файл tecmint.txt для тестирования команд. Давайте узнаем вывод файла с помощью команды cat, как показано ниже.

1. Базовый пример команды WC

Команда «wc» без передачи каких-либо параметров отобразит основной результат файла «tecmint.txt». Три числа, показанные ниже, — это 12 (количество строк), 16 (количество слов) и 112 (количество байтов) файла.

2. Подсчитайте количество строк

Чтобы подсчитать количество новых строк в файле, используйте параметр «-l», который печатает количество строк из данного файла. Скажем, следующая команда отобразит количество новых строк в файле. В выводе первое поле назначается как счетчик, а второе поле — это имя файла.

3. Отображение количества слов

Использование аргумента «-w» с командой «wc» позволяет распечатать количество слов в файле. Введите следующую команду для подсчета слов в файле.

4. Подсчитайте количество байтов и символов.

При использовании параметров «-c» и «-m» с командой «wc» будет выведено общее количество байтов и символов, соответственно, в файле.

5. Отображение длины самой длинной строки

Команда «wc» позволяет использовать аргумент «-L», его можно использовать для вывода длины самой длинной (количество символов) строки в файле. Итак, у нас есть самая длинная символьная строка («Scientific Linux») в файле.

6. Проверьте дополнительные параметры туалета.

Для получения дополнительной информации и помощи по команде wc просто запустите «wc –help» или «man wc» из командной строки.

6 Wc Command to Count Number of Lines, Words, and Characters in File

wc (short for word count) is a command line tool in Unix/Linux operating systems, which is used to find out the number of newline count, word count, byte and character count in the files specified by the File arguments to the standard output and hold a total count for all named files.

When you define the File parameter, the wc command prints the file names as well as the requested counts. If you do not define a file name for the File parameter, it prints only the total count to the standard output.

In this article, we will discuss how to use the wc command to calculate a file’s newlines, words, characters, or byte count with practical examples.

wc Command Syntax

The syntax of the wc command is shown below.

The followings are the options and usage provided by the wc command.

  • wc -l – Prints the number of lines in a file.
  • wc -w – prints the number of words in a file.
  • wc -c – Displays the count of bytes in a file.
  • wc -m – prints the count of characters from a file.
  • wc -L – prints only the length of the longest line in a file.

Let’s see how we can use the ‘wc‘ command with the few available arguments and examples in this article. We have used the ‘tecmint.txt‘ file for testing the commands.

Let’s find out the output of the tecmint.txt file using the cat command as shown below.

1. A Basic Example of WC Command

The ‘wc‘ command without passing any parameter will display a basic result of the ‘tecmint.txt‘ file. The three numbers shown below are 12 (number of lines), 16 (number of words), and 112 (number of bytes) of the file.

2. Count Number of Lines in a File

Count the number of newlines in a file using the option ‘ -l ‘, which prints the number of lines from a given file. Say, the following command will display the count of newlines in a file.

In the output, the first field is assigned as count and the second field is the name of the file.

3. Count Number of Words in a File

The -w argument with the wc command prints the number of words in a file. Type the following command to count the words in a file.

4. Count Number of Characters in a File

When using option -m with the wc command will print the total number of characters in a file.

5. Count Number of Bytes in a File

When using option -c will print the number of bytes of a file.

6. Display Length of Longest Line in File

The ‘wc‘ command allows an argument ‘ -L ‘, it can be used to print out the length of the longest (number of characters) line in a file.

So, we have the longest character line (‘Scientific Linux‘) in a file.

7. Check wc Command Options

For more information and help on the wc command, simply run the ‘ wc —help ‘ or ‘ man wc ‘ from the command line.

In this article, you’ve learned about the wc command, which is a simple command-line utility to count the number of lines, words, characters, and byes in text files. There are lots of such other Linux commands, you should learn and master your command-line skills.

Tutorial Feedback.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *