Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Unix, how do I get the line, word, or character count of a document?

In Unix, to get the line, word, or character count of a document, use the wc command. At the Unix shell prompt, enter: wc filename Replace filename with the file or files for which you want information. For each file, wc will output three numbers. The first is the line count, the second is the word count, and the third is the character count. For example, if you entered wc .login, the output would be something similar to the following: 38 135 847 .login To narrow the focus of your query, use one or more of the following wc options:

Option Entities counted
 -c  bytes
 -l  lines
 -m  characters
 -w  words

Note: In some versions of wc, the  -m  option will not be available or  -c  will report characters. However, in most cases, the values for  -c  and  -m  are equal.

For example, to find out how many bytes are in the .login file, you could enter: wc -c .login

You may also pipe standard output into wc to determine the size of a stream. For example, to find out how many files are in a directory, enter: /bin/ls -l | wc -l

For more information about wc, read its man page. To do this, at the Unix prompt, enter: man wc

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document adpb in domain all.
Last modified on August 22, 2008.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.