Linux Exercise 3 - Exploring File Contents
π 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
.zip
file)
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.zip
containing two files.
3. Use file
to determine the type of each file:
file /etc/hostsfile /bin/lsfile sample.zip
Observation: 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/hoststail -n 20 /var/log/syslog
Part 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 20
7. Use od
to dump the binary in different formats:
od -c /bin/ls # ASCII charactersod -x /bin/ls # Hexadecimalod -b /bin/ls # Octal
Part 4: Extracting and Viewing Text from Binaries
8. Use strings
to list readable text from the binary:
strings /bin/ls | head -n 20
9. Use xxd
to create a hex dump:
xxd /bin/ls | head -n 20
Part 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.zipOutput: sample.zip: Zip archive data, at least v2.0 to extractExplanation: 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/syslogOutput: (live log output appears)Explanation: Monitors new log entries in real-time.Observation: Useful for watching system activity as it happens.