Lesson 5: Create, copy, and move files — mkdir, touch, cp, mv
So far we've only looked; now we start changing things — exactly what you do when preparing a server: creating folders, copying config files, giving them the right name, and cleaning up. We'll meet five commands: mkdir (a new directory), touch (an empty file), cp (copies — the original stays), mv (m
Picture a cabinet: mkdir opens a new drawer, touch places a blank page in it, and cp photocopies a page so you keep both the original and the copy. mv moves the page somewhere else (or changes its title) — it's no longer in the old spot. rm throws the page in the trash, and on a server there's no trash bin to restore from.
- mkdir
- Creates a new directory (make directory). mkdir releases creates a folder named releases. Silent on success.
- touch
- Creates an empty file if it doesn't exist (and if it does — updates its modified time). Handy to create a fresh file from scratch.
- cp
- Copies a file: cp source dest. The original stays and a new copy is created. cp -r copies a whole directory too.
- mv
- Moves a file elsewhere, or renames it: mv old new. Unlike cp, the original isn't kept — the file simply moved/changed.
- rm
- Deletes a file: rm file. On a server there's no recycle bin — deletion is final, so check twice. rm -r deletes a whole directory (extra caution).