File Management  «Prev  Next»

Listing, Copying, and Removing Directories: Exercise

Objective: Use ls, cp, and rm to inspect a directory tree, make a separate copy, and remove only that copy.

Prepare a Practice Workspace

Use a terminal on a UNIX-like system with an account you control. No old course account or Telnet connection is required. Create a new, disposable workspace with ordinary directories and files. If the name below already exists, choose another name; do not reuse an unfamiliar directory. Run each setup command separately, and stop if one fails.

mkdir file-management-practice
cd file-management-practice
mkdir -p images/icons images/lines project
printf '%s\n' 'practice icon' > images/icons/sample.txt
printf '%s\n' 'practice line' > images/lines/sample.txt
printf '%s\n' 'practice setting' > images/.settings

Here, project exists and project/images does not. That destination state is important: copying images into the existing project directory should create project/images.

Tasks

  1. Check your working directory with pwd. List its entries, including hidden names, and inspect the original images tree recursively.
  2. Copy the entire images tree into project. Use the portable recursive spelling cp -R. Explain why the destination becomes project/images.
  3. Enter project. List its contents and recursively inspect the copied images tree, including .settings. Compare it with the original.
  4. Before removing anything, use pwd and a listing to confirm that you are in the practice workspace's project directory. Remove only the copied ./images tree with interactive recursive removal. Read each prompt before answering.
  5. Verify that the copy is gone, return one directory level, and verify that the original images tree still exists.

Record your commands and observations as you work. Pasting them into the response box is sufficient; recording a terminal session with script is optional and depends on the installed utility. There is no requirement to log out of your terminal.

Self-Assessment: 2 Points

  • 1 point: Correct listings and recursive copy, including verification of hidden content and the destination layout.
  • 1 point: Removal of only the copied tree, with evidence that the original remains.

This is a self-assessment, not an automatic grader. Submit your commands and observations to compare them with the model solution. Clicking Submit does not award points or execute shell commands.