count lines of file linux code example

Example 1: shell count number of lines

$ wc -l < /dir/file.txt
3272485

Example 2: shell script to count number of lines in a file

echo Enter the filename
read file
w=`cat $file | wc -w`
c=`cat $file | wc -c`
l=`grep -c "." $file`
echo Number of characters in $file is $c
echo Number of words in $file is $w
echo Number of lines in $file is $l

Example 3: count lines in files

find . -name '*.php' | xargs wc -l

Example 4: linux command to get number of lines in a file

wc -l 
# output =  
# to omit the file name in output
wc -l < 
# output = 

Tags:

Misc Example