HomeLinuxWc Command - Depend Variety of Strains, Phrases, and Characters

Wc Command – Depend Variety of Strains, Phrases, and Characters


wc (quick for phrase depend) is a command line device in Unix/Linux working techniques, which is used to search out out the variety of newline depend, phrase depend, byte and character depend within the recordsdata specified by the File arguments to the usual output and maintain a complete depend for all named recordsdata.

Once you outline the File parameter, the wc command prints the file names in addition to the requested counts. If you don’t outline a file identify for the File parameter, it prints solely the full depend to the usual output.

On this article, we are going to talk about the best way to use the wc command to calculate a file’s newlines, phrases, characters, or byte depend with sensible examples.

wc Command Syntax

The syntax of the wc command is proven under.

# wc [options] filenames

The followings are the choices and utilization offered by the wc command.

  • wc -l – Prints the variety of strains in a file.
  • wc -w – prints the variety of phrases in a file.
  • wc -c – Shows the depend of bytes in a file.
  • wc -m – prints the depend of characters from a file.
  • wc -L – prints solely the size of the longest line in a file.

Let’s see how we will use the ‘wc‘ command with the few accessible arguments and examples on this article. We now have used the ‘tecmint.txt‘ file for testing the instructions.

Let’s discover out the output of the tecmint.txt file utilizing the cat command as proven under.

$ cat tecmint.txt

Pink Hat
CentOS
AlmaLinux
Rocky Linux
Fedora
Debian
Scientific Linux
OpenSuse
Ubuntu
Xubuntu
Linux Mint
Deepin Linux
Slackware
Mandriva

1. A Fundamental Instance of WC Command

The ‘wc‘ command with out passing any parameter will show a primary results of the ‘tecmint.txt‘ file. The three numbers proven under are 12 (variety of strains), 16 (variety of phrases), and 112 (variety of bytes) of the file.

$ wc tecmint.txt

12  16 112 tecmint.txt

2. Depend Variety of Strains in a File

Depend the variety of newlines in a file utilizing the choice ‘-l‘, which prints the variety of strains from a given file. Say, the next command will show the depend of newlines in a file.

Within the output, the primary discipline is assigned as depend and the second discipline is the identify of the file.

$ wc -l tecmint.txt

12 tecmint.txt

3. Depend Variety of Phrases in a File

The -w argument with the wc command prints the variety of phrases in a file. Kind the next command to depend the phrases in a file.

$ wc -w tecmint.txt

16 tecmint.txt

4. Depend Variety of Characters in a File

When utilizing choice -m with the wc command will print the full variety of characters in a file.

$ wc -m tecmint.txt

112 tecmint.txt

5. Depend Variety of Bytes in a File

When utilizing choice -c will print the variety of bytes of a file.

$ wc -c tecmint.txt

112 tecmint.txt

6. Show Size of Longest Line in File

The ‘wc‘ command permits an argument ‘-L‘, it may be used to print out the size of the longest (variety of characters) line in a file.

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

$ wc -L tecmint.txt

16 tecmint.txt

7. Test wc Command Choices

For extra info and assistance on the wc command, merely run the ‘wc --help‘ or ‘man wc‘ from the command line.

$ wc --help
OR
$ man wc

wc Command Utilization

Utilization: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, phrase, and byte counts for every FILE, and a complete line if
a couple of FILE is specified.  A phrase is a non-zero-length sequence of
characters delimited by white area.

With no FILE, or when FILE is -, learn normal enter.

The choices under could also be used to pick which counts are printed, at all times in
the next order: newline, phrase, character, byte, most line size.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=F    learn enter from the recordsdata specified by
                           NUL-terminated names in file F;
                           If F is - then learn names from normal enter
  -L, --max-line-length  print the utmost show width
  -w, --words            print the phrase counts
      --help     show this assist and exit
      --version  output model info and exit

GNU coreutils on-line assist: <https://www.gnu.org/software program/coreutils/>
Full documentation at: <https://www.gnu.org/software program/coreutils/wc>
or accessible regionally by way of: data '(coreutils) wc invocation'

On this article, you’ve realized concerning the wc command, which is an easy command-line utility to depend the variety of strains, phrases, characters, and byes in textual content recordsdata. There are many such different Linux instructions, you need to study and grasp your command-line expertise.

If You Admire What We Do Right here On TecMint, You Ought to Take into account:

TecMint is the quickest rising and most trusted neighborhood website for any type of Linux Articles, Guides and Books on the net. Tens of millions of individuals go to TecMint! to look or browse the 1000’s of revealed articles accessible FREELY to all.

For those who like what you’re studying, please think about shopping for us a espresso ( or 2 ) as a token of appreciation.

Support Us

We’re grateful in your by no means ending help.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments