Linux › Module 2 › Lesson 2
File Operations (cp, mv, rm, cat)
Copy, move, delete, and read files with cp, mv, rm, and cat
Opening
The terminal is a file manager with no Recycle Bin
You can now pwd, ls -la, cd between ~ and /, and mkdir under $HOME. The next skills are how files actually move: read (cat, less, head), duplicate (cp), rename/move (mv), and destroy (rm). GUIs often offer Undo. rm usually does not. That is not toughness theater — it is why professionals read the path twice and why rm -rf / is a forbidden punchline, not a troubleshooting step. Everything in this lesson stays under $HOME/cyberlium-lab on a machine you own. File-ops literacy is not a reason to wipe system trees or "reset" someone else's host.
1. Read first: cat, less, and head
cat prints a file's entire contents to the terminal. It is perfect for short notes and for /etc/os-release on your own box. It is a poor pager for a 4,000-line log: the interesting error scrolls off the screen. less shows one screen at a time (space to page, / to search, q to quit) without modifying the file. head prints the first lines (head -n 20 file) so you can sample a log without drowning.
tail shows the end of a file — usually the newest lines if the file only appends. head and tail together are how you learn a format and then check the latest events. Reading is the safe default. Before cp, mv, or rm, cat or less the file (or ls -la the directory) so you are acting on the object you think you are.
Defenders live in read mode: you cannot copy evidence you have not identified, and you must not delete it. In the lab, that habit looks like: create a practice note, cat it, then mutate a copy — not the only original you care about.
2. cp and mv: copy versus relocate
cp makes a second object. cp notes.txt notes-backup.txt leaves the original. Directories need recursion: cp -r project project-copy copies the tree. Prefer copying into a destination you just listed with ls. If the destination path already exists as a file, many setups overwrite without a dramatic warning — another reason to ls first and to keep practice under $HOME/cyberlium-lab.
mv does not copy; it relocates the same inode when it can (same filesystem). In the same directory, mv draft.txt final.txt is a rename. Across directories, mv report.txt ~/Documents/ is a move. After mv, the old path is gone. That is the whole point — and the whole risk if pwd was wrong. Quote paths with spaces: mv "my notes.txt" "final notes.txt".
A safe habit: cp first when you might need the original, then mv the copy to a new name, then rm only the extra when you are sure. That sequence turns "I hope this rename is right" into a reversible drill.
3. rm is unforgiving — and rm -rf / is never the fix
rm removes a file. There is typically no Trash. rm -r directory deletes the directory and everything inside it. The flags -r (recursive) and -f (force, ignore missing files and many prompts) together are how people turn a typo into a wiped tree. rm -rf / aims at the filesystem root. On a system you should never run it. On a VM it is still a terrible habit: it trains your fingers to type catastrophe.
Wildcards make this sharper. rm *.log deletes every matching name in the current directory. rm * in the wrong pwd is a career story. Prefer: cd to the practice folder, ls the match (ls *.txt), then rm a named file you just created. Interactive rm -i asks before each delete on some systems — useful on boxes you care about. Never chmod 777 / to "make delete work."
If you need to clean a lab folder, delete named practice files one at a time, or remove a single directory you created (rm -r "$HOME/cyberlium-lab/file-ops/scratch") after pwd confirms you are not at /. Specificity is the safety feature.
4. Wrong vs right: "clean up the lab folder"
Failure mode — you created junk files during navigation practice:
Wrong
From an unknown pwd, run rm -rf * or paste rm -rf / from a forum "reset Linux" thread. Or chmod 777 / "so delete works." You destroy the VM, or worse, you destroy a real machine if you were not where you thought. Wildcards plus force plus root is how labs become reinstalls — and how bad habits escape the lab.
Right
pwd. Confirm you are in ~/cyberlium-lab (or a subfolder you made). ls -la. cat the small file you intend to drop. rm that filename only. Copy first if you might need it: cp notes.txt notes-backup.txt. Never rm -rf / and never chmod 777 /. Read, copy, rename, then delete one named object.
5. Practical: copy, read, rename, delete ONE practice file
Only under $HOME/cyberlium-lab on YOUR VM or WSL. If a command mentions / as a delete target, stop. You are not cleaning the OS. You are learning reversible file hygiene.
Command guide
Safe file-ops drill (your home lab folder only)
Stay in YOUR practice tree
Command — copy this
whoami cd ~ pwd mkdir -p "$HOME/cyberlium-lab/file-ops" cd "$HOME/cyberlium-lab/file-ops" pwd
Create and READ (do not start with rm)
Command — copy this
echo "cyberlium file-ops practice" > notes.txt cat notes.txt head -n 5 notes.txt
Optional command
less notes.txt # press q to quit if you open it
Optional command
Copy then rename (mv) — original preserved until you choose
Command — copy this
cp notes.txt notes-backup.txt ls -la mv notes-backup.txt notes-renamed.txt ls -la
Delete ONLY the extra copy you just made — not the tree
Command — copy this
rm notes-renamed.txt ls -la
notes.txt should still exist
Optional: sample end of a tiny file
Command — copy this
tail -n 1 notes.txt
NEVER:
Optional command
rm -rf / rm -rf * chmod 777 / rm with a path you have not verified via pwd and ls
Mission: backup before delete
In ~/cyberlium-lab/file-ops on your own machine: create notes.txt, cat it, cp to a backup, mv the backup to a new name, then rm only the renamed copy. End with notes.txt still present (ls -la to prove it). Write one rule: "I never run rm -rf / or chmod 777 /."
Stuck? Ask Cyberlium AI Mentor
If cp vs mv vs rm still collapses into "they all change files," ask Cyberlium AI Mentor for a hint — not a cheat sheet. Try: "Hint only: after cp a.txt b.txt, does a.txt still exist? After mv? After rm?" Practice answers on files you created under $HOME/cyberlium-lab only.
Navigation taught you where you are; this lesson taught you how objects move and why rm has no undo. You practiced cat/less/head before mutation, cp for copies, mv for rename/move, and a single named rm in $HOME. Next up — Text Editors (nano, vim basics) — because configs and notes are text, and you will need to change them without a GUI.
Knowledge Check
APPLY: A 20,000-line auth.log sits in a directory you own in lab. You want to skim without flooding the terminal or deleting anything. Best first tool?
Multiple choice
Knowledge Check
APPLY: You meant to rename lab-notes.txt to final-notes.txt in ~/cyberlium-lab. Which command does that without leaving a second copy?
Multiple choice
Knowledge Check
APPLY: True or False: If a blog says rm -rf / will "reset Ubuntu to factory settings," you should run it on your WSL or VM to start Module 2 clean.
True or False