Linux Exercise 3 - Exploring File Contents
📝 Linux Exercise: Exploring File Contents
Section titled “📝 Linux Exercise: Exploring File Contents”🎯 Objective
Section titled “🎯 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
Section titled “🔨 Task Instructions”Part 1: Identifying File Types
Section titled “Part 1: Identifying File Types”1. Choose several files from your system:
Section titled “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):
Section titled “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:
Section titled “3. Use file to determine the type of each file:”file /etc/hostsfile /bin/lsfile sample.zipObservation: Note what type each file is and why that matters.
Part 2: Inspecting Text Files
Section titled “Part 2: Inspecting Text Files”4. Use head and tail:
Section titled “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:
Section titled “5. Experiment with more lines:”head -n 20 /etc/hoststail -n 20 /var/log/syslogPart 3: Examining Binary Files
Section titled “Part 3: Examining Binary Files”6. Use objdump on a binary executable (/bin/ls):
Section titled “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:
Section titled “7. Use od to dump the binary in different formats:”od -c /bin/ls # ASCII charactersod -x /bin/ls # Hexadecimalod -b /bin/ls # OctalPart 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:”strings /bin/ls | head -n 209. Use xxd to create a hex dump:
Section titled “9. Use xxd to create a hex dump:”xxd /bin/ls | head -n 20Part 5: Viewing Full Content
Section titled “Part 5: Viewing Full Content”10. Use cat and less on a text file:
Section titled “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)
Section titled “📑 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.