Skip to the workspace
Pebellslearn by building
Navigation Basics  ›  Lesson

Creating and Deleting Files and Directories

Creating & Deleting Files / Dirs 12 minmkdir and touch create folders and files cheaply, while rm, rmdir and rm -r delete permanently, so deletes should be previewed first.

linux / Creating and Deleting Files and Directories

Explore each scene at your own pace.

01 · The rule

The rule

Creating and Deleting Files and Directories

Asha wants a folder for each season and an empty log file in each one. Later she'll want to clear out a season she no longer needs. Making things on Linux is quick and harmless. Removing them is just as quick, and there is no recycle bin to rescue you.

The rule

Creating is cheap; deleting is forever — look before you rm.

Creating:

$ cd ~/garden
$ mkdir summer                   # make one directory
$ mkdir -p seasons/2026/summer   # make the whole chain, parents included
$ touch summer/log.txt           # make an empty file
  • mkdir makes a directory. It fails if the parent doesn't exist yet, unless you add -p, which creates every missing level. -p also stays quiet if the directory already exists.
  • touch creates an empty file if the name is new. If the file already exists, it leaves the contents alone and only updates its "last modified" time.

Deleting:

$ rm summer/log.txt      # delete a file
$ rmdir summer           # delete an EMPTY directory
$ rm -r seasons          # delete a directory and everything inside it
  • rm removes files. Add -i to be asked about each one.
  • rmdir only removes empty directories. That makes it a safe choice: it refuses if anything is still inside.
  • rm -r (recursive) removes a directory together with its whole contents. rm -rf adds "force": no questions and no complaints about missing files. It is the most dangerous everyday command on the system.

Names with spaces need quotes. mkdir summer plans makes two folders, summer and plans, while mkdir "summer plans" makes one. Many people simply avoid spaces in file names and use hyphens instead, as in summer-plans.

Deleted files do not go to a trash folder. Once rm finishes, you can only get them back from a backup.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.