Lesson 3.3: Working with files and directories
Create, copy, move, rename and delete: touch, mkdir (-p), cp (-r), mv, rm (-r, -i) and rmdir; why there is no recycle bin on the command line.
17 min
You will learn to
- Create files with touch and directories with mkdir (-p)
- Copy files and whole directories with cp and cp -r
- Move and rename with mv
- Delete safely with rm -i, rmdir and rm -r
Key terms
- Source and destination
- For cp and mv, the first argument is what you copy or move (source), the last is where it goes (destination). If the destination is an existing directory, the file keeps its name inside it.
- Recursive (-r)
- Acting on a directory and, inside it, on every directory and file, all the way down.
- Overwrite
- Replacing an existing file's contents. cp and mv overwrite a destination file without asking unless you add -i.
- Interactive (-i)
- Asks for confirmation before each overwrite or deletion: rm -i, cp -i, mv -i.
- No recycle bin
- rm deletes immediately and permanently; there is no trash folder to restore from. Only backups can bring the data back.
← Absolute and relative paths · All lessons · Spaces in paths and file names →