Counting and Checking: wc and file

wc: word count

wc counts the lines, words and bytes in a file, in that order:

wc poem.txt

In the terminal

student@vulntech:~$ wc poem.txt
  4  28 139 poem.txt

Ask for just one number with an option:

OptionCounts
-lLines
-wWords
-cBytes
wc -l numbers.txt
wc -w poem.txt shopping.txt

In the terminal

student@vulntech:~$ wc -l numbers.txt
200 numbers.txt
student@vulntech:~$ wc -w poem.txt shopping.txt
 28 poem.txt
  5 shopping.txt
 33 total

file: what kind of file is it?

On Linux, a file's name doesn't decide what it is: photo.jpg could really be a text file. file looks inside and tells you:

file poem.txt
file /bin/busybox
file /etc
file /usr/share/man/man1/ls.1.gz

In the terminal

student@vulntech:~$ file poem.txt
poem.txt: ASCII text
student@vulntech:~$ file /bin/busybox
/bin/busybox: ELF 32-bit LSB pie executable, Intel i386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-i386.so.1, BuildID[sha1]=86b5b12b4734a66df32744184ded767ce15fb52b, stripped
student@vulntech:~$ file /etc
/etc: directory
student@vulntech:~$ file /usr/share/man/man1/ls.1.gz
/usr/share/man/man1/ls.1.gz: gzip compressed data, max compression, from Unix, original size modulo 2^32 8149

Tip: Security analysts use file all the time: a downloaded invoice.pdf that file calls an executable is a big red flag.

Remember: wc -l counts lines. file tells you what a file really is.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…