AWS re/Start Lab · Linux

Working with the File System

Create a company folder structure with directories and files, then reorganize it by copying, moving, and deleting files and directories.

Lab Summary

Connected via PuTTY (as described in Lab 225). Built a CompanyA folder structure with three departments (Finance, HR, Management) and their files. Then reorganized the structure by moving Finance and Management under HR, and creating a new Employees folder.

Build the Structure

Created the CompanyA directory with three subdirectories and six CSV files using mkdir and touch.

Reorganize

Moved Finance and Management under HR, created Employees, and relocated files using cp, mv, rm, and rmdir.

Step-by-Step Walkthrough

Detailed record of each task performed during the lab.

01

SSH Connection

  • Connected to the EC2 instance via PuTTY following the process described in Lab 225.
02

Create the Folder Structure

  • Ran pwd to confirm the current directory was /home/ec2-user.
  • Created the top-level folder with mkdir CompanyA.
  • Changed to it with cd CompanyA.
  • Created all subdirectories at once with mkdir Finance HR Management.
  • Verified with ls: Finance, HR, Management.
  • Changed to HR with cd HR and created files with touch Assessments.csv TrialPeriod.csv.
  • Navigated to Finance with cd ../Finance and created touch Salary.csv ProfitAndLossStatements.csv.
  • Went back to CompanyA with cd .. and created files in Management using relative paths: touch Management/Managers.csv Management/Schedule.csv.
  • Verified the entire structure with ls -laR.
The touch and ls commands can be used two ways: directly in the current folder, or with a relative path (e.g., touch Management/Managers.csv from the parent directory).
03

Delete and Reorganize Folders

  • Confirmed location with pwd: /home/ec2-user/CompanyA.
  • Copied Finance into HR with cp -r Finance HR.
  • Verified the copy with ls HR/Finance.
  • Attempted to remove Finance with rmdir Finance, which failed because the directory was not empty.
  • Removed the files inside Finance with rm Finance/ProfitAndLossStatements.csv Finance/Salary.csv.
  • Successfully removed the empty directory with rmdir Finance.
  • Verified with ls: only HR and Management remained.
  • Moved Management into HR with mv Management HR.
  • Verified with ls . HR/Management.
  • Changed to HR with cd HR.
  • Created the Employees folder with mkdir Employees.
  • Moved the assessment files with mv Assessments.csv TrialPeriod.csv Employees.
  • Verified the final structure with ls . Employees: HR now contains Employees, Finance, and Management.
The rmdir command only works on empty directories. To remove a non-empty directory, either delete its contents first or use rm -r to recursively remove everything.

Command Reference

Commands used in this lab for file system management.

cmd

mkdir

Creates one or more directories.

  • mkdir folder1 folder2 : Create multiple directories at once
cmd

touch

Creates empty files or updates timestamps of existing files.

  • touch file1.csv file2.csv : Create multiple files at once
  • touch folder/file.csv : Create a file using a relative path
cmd

cp

Copies files or directories.

  • -r : Copy recursively (required for directories)
cmd

mv

Moves or renames files and directories.

  • mv source destination : Move a file or directory
  • mv file1 file2 folder/ : Move multiple items at once
cmd

rm

Removes files.

  • rm file1 file2 : Remove specific files
  • -r : Remove directories and their contents recursively
cmd

rmdir

Removes empty directories only. Fails if the directory contains files.

cmd

ls -laR

Lists all files recursively with detailed information (permissions, owner, size, date).

Key Learnings

What Was Learned

How to create directory structures with mkdir and populate them with files using touch.
How to copy directories recursively with cp -r and move files with mv.
The difference between rmdir (empty directories only) and rm -r (recursive removal).
How to use relative paths with commands like touch and ls to work with files in other directories.

Technical Conclusion

This lab covered the essential file system operations in Linux: creating, copying, moving, and deleting files and directories. These are fundamental skills for organizing and maintaining file structures on Linux servers.

The key distinction between rmdir and rm -r is a safety feature: rmdir prevents accidental deletion of directories that still contain data, while rm -r is more powerful but requires caution.