How to count word in file in linux PC?

Asked By 10 points N/A Posted on -
qa-featured

I have some job to perform that I need to maintain file size, number of line, number of word etc,

So how I count words, line or letter in Linux PC? 

SHARE
Best Answer by Taylor Laura
Answered By 0 points N/A #134154

How to count word in file in linux PC?

qa-featured

Hi Baker,

There is a nice command for you in Red Hat Linux System, this command helps you to collect information about total letters in the file also. wc command can solve your problem.

Command:

wc -l    <file name>    for only line count
wc -w   <file name>   for only count word
wc -c    <file name>   for only character count
 

# wc <file name>   All information together.

Britnu Salu

Best Answer
Best Answer
Answered By 0 points N/A #196506

How to count word in file in linux PC?

qa-featured

Hi Mich!

When checking the size of your directories and files, your need the ‘ls’ command. Typing 'ls' in your current directory will give you the list of the directory’s contents.
 
It displays the file names, the permissions, the date of the files were made and the size.  
 
The format of using this is:
 
ls [OPTION] [FILE]
 
Common options:
-a, –all
– means to display hidden files (they usually start with a dot)
–author
– means to display the author of each file
-b, –escape
– will display octal escapes if your file name contains nongraphic characters
-d, –directory
– will display directories instead of the file contents
-f
– this will not sort the file list
-R
– will display the subdirectories recursively
-S
– this will display sorted list according to file size
– t
– will display list according to modification time
–help
– will display the manual and help page of the ‘ls’ command
 
Example output of the 'ls' command below.  The file size is represented in kilobytes or K.
 
 
For more information about the 'ls' command, just type 'man ls' in your Linux command prompt and the manual page for 'ls' will be displayed.
 
Another option for checking file size is using the command ‘du’.  This command will display a summary of the disk usage of each file.  Do this by typing:
 
du [OPTION] [FILE]
 
Commonly used option:
-s, summarize – this will show a total size for each argument
 
For counting words, lines and characters within a file, you might want to check shell scripting.  There are a lot of tutorials for this online, and it’s actually easy to do.  With shell scripting you won’t need to type a lot commands just to check all the things you needed to know in you Linux system.  
 
By executing one script it will automate all the checking for you.
 

Login/Register to Answer

Related Questions