file—determines the type of a file by looking at its contents

file [ -vbczL ] [ -f namefile ] [ -m magicfiles ] file…

file performs a series of tests on each filename in an attempt to determine what it contains. If the contents of the file appear to be ASCII text, file examines the first 512 bytes and tries to guess its language.

Example A.26.
1  file bin/ls
					/bin/ls:sparc pure dynamically linked executable
2  file go
					go:     executable shell script
3  file junk
					junk:   English text
				

Explanation

  1. ls is binary file dynamically linked when executed.

  2. go is a shell script.

  3. junk is a file containing ASCII text.

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.