Linux wc CommandLinux wc command helps in counting the lines, words, and characters in a file. It displays the number of lines, number of characters, and the number of words in a file. Mostly, it is used with pipes for counting operation. Syntax:Options:Some useful command line options supported by the wc command are as following: -c, --bytes: It is used to print the byte counts. -m, --chars: It is used to print the character counts. -l, --lines: It is used to print the newline counts. --files0-from=F: It is used to read input from specified files. -L, --max-line-length: It is used to print the maximum display width. -w, --words: It is used to print the word counts. --help: It is used to display the help manual. --version: It is used to display the version information. Examples of the wc CommandLet's see the following examples of the wc command:
Display count information of a fileTo display the complete count information of a file, execute the command without any argument. It will display the number of lines, words, and bytes from the file. Execute the command as follows: Consider the below command: The above command will display the number of lines, number of words, number of bytes, and file name from the file 'exm.txt'. Consider the below output: Display count information of multiple filesTo display the complete count information of multiple files at once, specify the file names after space (' '). It is executed as follows: Consider the below example: The above command will display the number of words, the number of characters, and the number of the bytes from the files 'exm.txt' and 'marks.txt'. Consider the below output: Display the number of lines in a fileThe '-l' option is used to display the number of lines in a file. It is executed as follows: Consider the below example: The above command will display the number of lines from 'exm.txt'. Consider the below output: Display the number of characters in a fileThe '-m' option is used to display the number of characters in a file. It is executed as follows: Consider the below example: The above command will display the number of words from the file 'exm.txt'. Consider the below output: Display the number of bytes in a fileThe '-c' option is used to display the number of bytes in a file. It is executed as follows: Consider the below example: The above command will display the number of bytes in a file. Consider the below output: Display the number of words in a fileThe '-w' option is used to display the total number of words from a file. It is executed as follows: Consider the below example: The above command will display the total number of words from the file 'exm.txt'. Consider the below output: Count the number files in a directoryTo count the number of files and folders in a directory, combine the wc command with the ls command. Execute it as follows: The above command will display the count of the files from the current working directory. Consider the below output: Display the length of the longest lineThe '-L' option is used to display the length of the longest line from a file. It is executed as follows: Consider the below example: The above command will display the length of the longest line of the file 'exm.txt'. Consider the below output: Next TopicLinux od
|