Linux Labs

First steps / Stage 7 of 15

Creating and organising files

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 10 · on a machine · 6 min

Deleting and filename patterns

You can delete one file, a directory, or many files at once picked by a filename pattern.

rm deletes a file at once. The command line has no trash to restore it from. rmdir deletes an empty directory and refuses if anything is inside, which is a safeguard. rm -r deletes a directory with its contents: run it only when you know exactly what is in there.

When there are many files, a filename pattern picks them. The asterisk stands for any part of a name: *.tmp means "every name ending in .tmp". The shell replaces the pattern with the matching names in the current directory — the lesson "Help and the shell" covers how.

bash
ls *.tmp      # which files the pattern picks
rm -i *.tmp   # delete, asking about each file
Warning

A pattern in rm deletes everything it matches. List the files with ls and the same pattern first, then delete.

Exercise · do it

Rename and clear out temporary files

In ~/file-lab/handoff, rename notes.txt to README.txt and delete every temporary *.tmp file. Leave the source directory alone: it holds the originals.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Rename notes.txt to README.txt not done yet
  • Delete the temporary files from handoff only not done yet

Step goals

0 of 2
  • Rename notes.txt to README.txt — not done yet
  • Delete the temporary files from handoff only — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Rename notes.txt to README.txt — not done yet
  • Delete the temporary files from handoff only — not done yet
Loading…