Another command related to the contents of files is wc. It is used to count the number of lines, words and characters in a file. If you use it like this example you will get the number of lines, words and bytes (characters in a "text" file) of a file
wc file-name
For getting the result of only one of the three possible outputs above you have to give some option:
- For lines output:
wc -l file-name
- For words output:
wc -w file-name
- For bytes (characters in a "text" file:
wc -c file-name
or
wc -w file-name
Another interesing option allows you to get the length of the longest line in the file:
wc -L file-name
You can give more than one file name in your command line; the output will have the file name appended to the results of the counting.
No comments:
Post a Comment