Linux Commands – wc

Linux Commands – wc

Linux Commands – wc

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed watch command in Linux which is used to run a command repeatedly, displaying its output and errors (the first screenful).

https://cloudaffaire.com/linux-commands-watch/

In this blog post, we will discuss wc command in Linux. wc command counts the number of bytes, characters, whitespace-separated words, and newlines in each given FILE or standard input and outputs the result in standard output. wc command prints one line of counts for each file, and if the file was given as an argument, it prints the file name following the counts. The counts are printed in this order: newlines, words, characters, bytes, maximum line length. By default, wc prints three counts: the newline, words, and byte counts.

Linux Commands – wc:

You can use wc command to print total numbers of newline, words, and byte in a file. If more than one FILE is given, wc prints a final line containing the cumulative counts, with the file name total.

You can use wc -c or –bytes options to print only the byte counts.

You can use wc -m or –chars options to print only the character counts.

You can use wc -w or –words options to print only the word counts.

You can use wc -l or –lines options to print only the newline counts.

You can use wc -L or –max-line-length to print the length of the longest line.

You can use wc –files0-from=FILE option which disallow processing files named on the command line, and instead process those named in file FILE; each name being terminated by a zero byte (ASCII NUL). This is useful when the list of file names is so long that it may exceed a command line length limitation. In such cases, running wc via xargs is undesirable because it splits the list into pieces and makes wc print a total for each sublist rather than for the entire list. One way to produce a list of ASCII NUL terminated file names is with GNU find, using its -print0 predicate. If FILE is ‘-‘ then the ASCII NUL terminated file names are read from standard input.

Hope you have enjoyed this article. In the next blog post, we will discuss the date command in Linux.

 

Leave a Reply

Close Menu