Software & Apps Linux Count the Number of Words in a File Using the 'wc' Command Count words, lines, and bytes within text files using a two-character command by Juergen Haas Writer Former Lifewire writer Juergen Haas is a software developer, data scientist, and a fan of the Linux operating system. our editorial process Juergen Haas Updated on February 19, 2020 Tweet Share Email Linux Switching from Windows The Linux wc command counts the total number of words in a file. This command only works on plain-text files. More complex files, like documents saved in Rich Text Format, contain additional command codes that, although you don't see them when you open the file in an RTF-capable word processor, are nevertheless embedded in the document. How to Use the 'wc' Command The basic usage of the wc command is as follows: wc filename For example, a text file titled declaration.txt contains a key line from the Declaration of Independence. Executing the command: wc declaration.txt reveals data about the text within that file: The command displays three numbers — 2 35 211 — plus the filename. Those values indicate three contextual data points: The first number counts the number of new lines of charactersThe second number counts the number of wordsThe third number counts the number of bytes (i.e., the number of characters, visible or not) Get the Total Word Count From Several Files The wc command supports several filename arguments. For example, if we duplicate the declaration.txt as declaration2.txt, then run the wc command on both files, we'll see the totals for each and then the totals for both: Command Switches Adding a command switch refines the results of the wc command. It supports: -c: Displays only the number of bytes and the filename-m: Displays only the number of characters-l: Displays only the number of lines-w: Displays only the number of words A line is a logical construct; it's not affected by word wraps. In the example declaration.txt, we inserted a hard line break to show the entire quote on the screen, which is why the wc command lists two lines. If we had not inserted the manual line break, the quote would have stretched off the side of the screen, but it would have shown only one line of text. Was this page helpful? Thanks for letting us know! Get the Latest Tech News Delivered Every Day Email Address Sign up There was an error. Please try again. You're in! Thanks for signing up. There was an error. Please try again. Thank you for signing up. Tell us why! Other Not enough details Hard to understand Submit