Creating, Removing, Copying and Moving Files

** Git & GitHub in Practice: Push, Pull & Heal (Part 1 of 3)
Lesson Content
0% Complete

Learning Objectives

  • Create folders and empty files using mkdir and touch
  • Delete files and folders safely using rm, rmdir, and rm -r
  • Copy a file without disturbing the original using cp
  • Move and rename files using mv

Key Topics Covered

CommandExplanation
mkdirCreates a new, empty directory (folder) at the path you specify. Use mkdir -p parent/child to create nested folders in one go, even if the parent doesn’t exist yet.
touchCreates a new, empty file if it doesn’t already exist. If the file exists, it doesn’t touch the content — it just updates the file’s “last modified” time.
rmdirDeletes a directory, but only if it’s completely empty. If it has files or folders inside, this command will fail — it’s a safety check against accidental deletion.
rmDeletes a single file permanently. There’s no recycle bin here — once deleted, it’s gone, so double-check the filename before running it.
rm -rDeletes a directory along with everything inside it (files and subfolders), recursively. This is more powerful than rmdir but also riskier since it removes non-empty folders too.
cpCopies a file or folder to a new location, leaving the original untouched. Use cp -r when copying a directory, so its contents come along with it.
mvMoves a file/folder to a different location, or renames it if you keep it in the same location but give it a new name. Unlike cp, no copy is left behind — the original path stops existing.

Course Outline