π Linux Exercise: Exploring File Contents
π― Objective
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.
π¨ Task Instructions
Part 1: Identifying File Types
1. Choose several files from your system:
- A text file (e.g.,
/etc/hosts) - A binary executable (e.g.,
/bin/ls) - A compressed archive (e.g., a
.zipfile)
2. Create a zip file for analysis (if you donβt already have one):
zip sample.zip /etc/hosts /etc/resolv.conf- This creates
sample.zipcontaining two files.
3. Use file to determine the type of each file:
file /etc/hosts
file /bin/ls
file sample.zipObservation: Note what type each file is and why that matters.
Part 2: Inspecting Text Files
4. Use head and tail:
- View the first 10 lines of a text file:
head /etc/hosts- For
tail, use a file that is regularly updated, e.g., the system log:
sudo tail -f /var/log/syslog- Observe new log entries as they appear in real-time.
5. Experiment with more lines:
head -n 20 /etc/hosts
tail -n 20 /var/log/syslogPart 3: Examining Binary Files
6. Use objdump on a binary executable (/bin/ls):
- Show headers:
objdump -x /bin/ls- Disassemble a few instructions:
objdump -d /bin/ls | head -n 207. Use od to dump the binary in different formats:
od -c /bin/ls # ASCII characters
od -x /bin/ls # Hexadecimal
od -b /bin/ls # OctalPart 4: Extracting and Viewing Text from Binaries
8. Use strings to list readable text from the binary:
strings /bin/ls | head -n 209. Use xxd to create a hex dump:
xxd /bin/ls | head -n 20Part 5: Viewing Full Content
10. Use cat and less on a text file:
- Print the whole file:
cat /etc/hosts- Scroll interactively:
less /etc/hostsπ Protocol (What to Hand In)
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.
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.