Skip to content

Linux Investigating File Contents

The file command inspects a file and tells you what type it is, without relying solely on the file extension.

Terminal window
file filename
Terminal window
$ file notes.txt
notes.txt: ASCII text
$ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64

What you learn:

  • Whether a file is text, binary, executable, archive, image, etc.
  • Helpful for understanding what tools to use to inspect the file further.

The head command shows the first lines of a file. Default is 10 lines, but you can adjust it.

Terminal window
head filename
head -n 20 filename # show first 20 lines
Terminal window
$ head notes.txt
This is the first line of the file.
This is the second line.
...

What you learn:

  • Quickly inspect the start of a text file or log file.
  • Useful to check headers or file metadata in plain-text files.

The tail command shows the last lines of a file. Very useful for log files.

Terminal window
tail filename
tail -n 50 filename # last 50 lines
tail -f filename # follow live updates
Terminal window
$ tail /var/log/syslog
Sep 7 12:34:45 kernel: ...

What you learn:

  • Monitor logs in real-time (-f).
  • Quickly see recent activity in large files.

objdump is a tool for examining binary files and executables. You can look at headers, disassembly, or raw content.

Terminal window
objdump -d filename # disassemble executable
objdump -x filename # show all headers
Terminal window
$ objdump -d /bin/ls | head -n 10

What you learn:

  • CPU instructions in binaries (-d).
  • Section headers, symbols, and other metadata (-x).
  • Useful for reverse engineering or debugging compiled programs.

od stands for octal dump. It can display file contents in various number formats.

Terminal window
od -c filename # show ASCII characters
od -x filename # show hexadecimal
od -b filename # show octal bytes
Terminal window
$ od -c notes.txt
0000000 T h i s i s t e x t \n

What you learn:

  • Low-level view of file contents.
  • See hidden characters, binary data, or encoding issues.

  • strings → extracts readable ASCII strings from binaries:
Terminal window
strings /bin/ls
  • xxd → creates a hex dump and reverse:
Terminal window
xxd filename
xxd -r filename.hex # convert hex back to file
  • less → interactively scroll through files:
Terminal window
less filename
  • cat → concatenate and print the full file:
Terminal window
cat filename

CommandPurpose
fileIdentify file type
headView first lines
tailView last lines or follow logs
objdumpInspect executables/binaries
odView raw data in octal/hex/binary
stringsExtract printable strings from binary
xxdHex dump and reverse
lessBrowse large files interactively
catPrint entire file
These commands together allow you to explore any file type, from plain text to compiled binaries, giving both high-level and low-level views.