~/shio.sh/learn/moving-and-removing $ ./read
chapter 05 · learn the terminal
Moving and removing (mv, cp, rm)
mv moves and renames. cp copies. rm removes — quietly and without asking. We'll handle it with care.
$ mv — move (or rename)
mv takes two arguments: where the file is, and where it should go. If the destination is a folder, the file moves there. If it's a new name in the same folder, the file is renamed.
mv notes.txt projects/— move into theprojectsfoldermv notes.txt diary.txt— rename todiary.txt
› try: mv notes.txt diary.txt
$ cp — copy
cp is the same shape as mv, but it copies instead of moving. For folders, you need -r (recursive) so it copies everything inside too.
cp diary.txt diary.bak— copy a single filecp -r projects backup— copy a folder and its contents
› try: cp notes.txt notes.bak
$ rm — remove, with care
rm deletes a file. There's no trash, no undo, no "are you sure?" — just silence. This is the most common command people regret typing.
For folders, you need -r (recursive). The classic horror story is rm -rf /, which would attempt to delete everything. Don't be that person.
rm hello.txt— delete one filerm -r notebook— delete a folder and everything in it
› try: rm notes.txt
Two small habits to keep:
- Type the path you mean to delete, look at it, then press Enter.
- If you're nervous, run
lsfirst to confirm you have the right name.
$ a quiet kind of power
These three — mv, cp, rm — let you reshape your filesystem with the same effort it takes to type three letters. That's the thing about the terminal: small inputs, large effects. Worth respecting.
~/shio.sh/learn/moving-and-removing $ cd ..