Get more file info!

The wc bash command gives more info on the contents of a file. A simple man command on wc (man wc) will give:

wc: print newline, word, and byte counts for each file

I create a file named file1

wc file1

This command gives a weird output like:

 2 5   25 file1

Here 2 is the number of newline characters in the file

5 is the number of space separated words

25 is the size of file in bytes (= number of characters in the file iff each character = 1 byte)

file1 is the name of the file under consideration

Here’s a nifty trick.

$ printf ‘The %4$s file has %2$03s words over %1$s lines. Size: %3$s bytes.\n’ `wc file1`

  

This outputs

The file1 file has 025 words over 2 lines. Size: 25 bytes

$

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: