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
mkdir is opening a new drawer. touch is placing a blank page in the drawer. cp is photocopying a page and keeping both the original and the copy. mv is taking the page and moving it (or changing its title) — the original page is no longer in its old spot. rm is throwing it 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).