Skip to content

Linux Exercise 3 - Exploring File Contents

📝 Linux Exercise: Exploring File Contents

Section titled “📝 Linux Exercise: Exploring File Contents”

Students will practice inspecting files in Linux using commands such as file, head, tail, objdump, od, strings, xxd, less, and cat.
They will create a protocol documenting all commands, outputs, and observations.


  • A text file (e.g., /etc/hosts)
  • A binary executable (e.g., /bin/ls)
  • A compressed archive (e.g., a .zip file)

2. Create a zip file for analysis (if you don’t already have one):

Section titled “2. Create a zip file for analysis (if you don’t already have one):”
Terminal window
zip sample.zip /etc/hosts /etc/resolv.conf
  • This creates sample.zip containing two files.

3. Use file to determine the type of each file:

Section titled “3. Use file to determine the type of each file:”
Terminal window
file /etc/hosts
file /bin/ls
file sample.zip

Observation: Note what type each file is and why that matters.


  • View the first 10 lines of a text file:
Terminal window
head /etc/hosts
  • For tail, use a file that is regularly updated, e.g., the system log:
Terminal window
sudo tail -f /var/log/syslog
  • Observe new log entries as they appear in real-time.
Terminal window
head -n 20 /etc/hosts
tail -n 20 /var/log/syslog

6. Use objdump on a binary executable (/bin/ls):

Section titled “6. Use objdump on a binary executable (/bin/ls):”
  • Show headers:
Terminal window
objdump -x /bin/ls
  • Disassemble a few instructions:
Terminal window
objdump -d /bin/ls | head -n 20

7. Use od to dump the binary in different formats:

Section titled “7. Use od to dump the binary in different formats:”
Terminal window
od -c /bin/ls # ASCII characters
od -x /bin/ls # Hexadecimal
od -b /bin/ls # Octal

Part 4: Extracting and Viewing Text from Binaries

Section titled “Part 4: Extracting and Viewing Text from Binaries”

8. Use strings to list readable text from the binary:

Section titled “8. Use strings to list readable text from the binary:”
Terminal window
strings /bin/ls | head -n 20
Terminal window
xxd /bin/ls | head -n 20

  • Print the whole file:
Terminal window
cat /etc/hosts
  • Scroll interactively:
Terminal window
less /etc/hosts

Each student must create a protocol (log) containing:

  • Command executed
  • Output received (full or partial if very long)
  • Explanation (1–2 sentences) of what the command did
  • Observation/interpretation of what they learned

Example:

Command: file sample.zip
Output: sample.zip: Zip archive data, at least v2.0 to extract
Explanation: Identified sample.zip as a compressed archive file.
Observation: Shows that zip files are binary and need archive tools to inspect contents.
Terminal window
Command: sudo tail -f /var/log/syslog
Output: (live log output appears)
Explanation: Monitors new log entries in real-time.
Observation: Useful for watching system activity as it happens.