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 your file manager
No drag-and-drop. Instead you get precise commands that scripts can repeat. cp, mv, rm, and cat are the daily drivers—powerful, fast, and unforgiving if you typo.
1. Read a File: cat
cat prints file contents to the screen. cat readme.txt cat /etc/hostname For long files, use less readme.txt (space to scroll, q to quit).
2. Copy: cp
cp copies files or folders. cp notes.txt notes-backup.txt cp -r myfolder myfolder-copy — -r for directories (recursive)
3. Move or Rename: mv
mv moves a file—or renames it if you stay in the same folder. mv draft.txt final.txt mv report.txt ~/Documents/
4. Delete: rm
rm removes files. There is usually no Recycle Bin. rm old.log rm -r temp_folder — delete a directory and everything inside
The famous mistake
Never run rm -rf / as root unless you are trying to destroy the system. Double-check paths. Use rm -i for interactive confirm on important boxes.
5. Wildcards
The asterisk * matches many files. ls *.txt — all text files here rm log_* — delete files starting with log_ Wildcards are convenient—and dangerous with rm. Slow down.
Knowledge Check
Which command copies a file?
Multiple choice
Knowledge Check
How do you rename file old.txt to new.txt in the same folder?
Multiple choice
Knowledge Check
True or False: rm usually sends files to a Trash folder you can restore later.
True or False