Chapter 2: Filesystem Management

Bash for Cybersecurity

Learning objectives

  1. Resolve absolute and relative paths in a supplied directory tree.
  2. Create, move, copy, rename, and remove files safely.
  3. Explain file types, attributes, hard links, and symbolic links.
  4. Inspect hidden files as data and edit an independent configuration copy.
  5. Organize a working tree and find files within an explicit search root.

Chapter flow

  1. Paths and Navigation
  2. Managing Files
  3. File Attributes & Links
  4. Hidden Files and Configuration
  5. Finding and Organizing Files

One supplied workspace

workspace/
├── inputs/    preserved synthetic originals
├── reports/   reviewed and generated copies
└── scratch/   disposable experiments

Run each lesson's supplied setup in Bash. Use the real VM for course work.
Use your persistent course workspace for the graded lab and homework.

Trace before changing files

cd reports
pwd
cd ../inputs
pwd
cd ..

A relative path starts at the working directory.
Quote a directory name containing spaces: cd 'host reports'.

Create, copy, move, verify

mkdir -p reports/drafts
cp -p inputs/host.conf reports/drafts/host.conf
mv reports/drafts/host.conf reports/host_review.conf
cat inputs/host.conf

A destination that already exists may be replaced. Inspect it first.
A copied file is not automatically a complete forensic record.

Remove an explicit disposable file

touch scratch/discard.txt
ls -l ./scratch/discard.txt
rm ./scratch/discard.txt

rm does not use the desktop Trash.
rmdir refuses a nonempty directory.
Avoid wildcard or recursive deletion in this introductory workflow.

Compare file relationships

Relationship Meaning
Copy A separate file with its own identity.
Hard link Another directory entry for the same file.
Symbolic link A separate entry holding a target pathname.

ls -li exposes inode numbers; readlink prints a stored target.
A relative symbolic target starts at the link's containing directory.

Preserve configuration as data

ls -a inputs
cp -p inputs/.audit.conf reports/audit_working.conf
diff inputs/.audit.conf reports/audit_working.conf

Edit only the working copy using the Tooling editor.
diff returns zero for a match and one for an expected difference.
A hidden name does not protect secrets; do not source unfamiliar files.

Bound a discovery query

find inputs -type f -name '*.txt' -print
find inputs -type f -name '.*' -print
find reports -type l -print

Quote the pattern and keep an explicit search root.
An empty result or a permission diagnostic limits your conclusion.
Keep discovery separate from deletion or command execution.

Topic references

Linuxize: cp,
mv,
rm,
links,
and find.

Original synthetic fixtures and practice tasks; see lesson source notes.