← Operating Systems from Zero: Linux, Windows and macOS

Video coming soon

The written lesson below is ready now. The video is being published on our YouTube channel.

Follow ChangeCV on YouTube →

Lesson 2 of 6

Work with files: cp, mv, rm, cat and grep

Copy, move, delete, read and search files from the terminal, with an office-desk analogy and a clear warning that rm has no recycle bin. Shown on Linux, macOS and Windows.

The idea in plain words

Think of an office desk. cp is the photocopier: you get a copy and the original stays where it is. mv is carrying a paper to another drawer, or simply writing a new label on it.

rm is the paper shredder, and there is no recycle bin. cat is reading the page, and grep is a highlighter that finds a word for you.

Commands in this lesson

cp report.txt report-backup.txt
Copy a file and keep the original. Add -r to copy a folder. In PowerShell the full name is Copy-Item.
mv report.txt archive/
Move a file to another folder, or rename it. In PowerShell the full name is Move-Item.
rm report-backup.txt
Delete a file. There is no recycle bin, so it is gone. Add -r for a folder. In PowerShell the full name is Remove-Item.
cat server.log
Print a file on the screen. In PowerShell the full name is Get-Content.
grep -n ERROR server.log
Show the lines of a file that contain a word, with line numbers. In PowerShell use Select-String.

Written notes from the video

Why file commands matter

You can find your way around. Now, what can you actually do with files? This is Operating Systems from zero, episode two: working with files. Five commands to copy, move, delete, read and search, on Linux, macOS and Windows.

The office desk analogy

Think of an office desk. cp is the photocopier. You get a copy, and the original stays where it is. mv is carrying a paper to another drawer. Or simply writing a new label on it. rm is the paper shredder. There is no recycle bin. cat is reading the page. And grep is a highlighter that finds a word for you.

Command 1: cp

Command one: cp, short for copy. cp report.txt report-backup.txt makes a copy next to the original. To copy a whole folder, add -r. In Windows PowerShell, cp works too. It is a short name for Copy-Item.

Command 2: mv

Command two: mv, short for move. mv report-backup.txt report-2026.txt gives the file a new name. Moving a file inside the same folder is how you rename it. mv also moves files into other folders. In PowerShell the full name is Move-Item, and mv works there too.

Command 3: rm

Command three: rm, short for remove. rm report-2026.txt deletes the file. There is no trash can. When it is gone, it is gone. To delete a folder, add -r. Always double check the name first.

Command 4: cat

Command four: cat. cat prints the contents of a file on the screen. It is perfect for short files, like a report or a settings file. The name comes from concatenate, which means to join files together.

Command 5: grep

Command five: grep. It searches inside a file for a word, and prints the lines that match. The -n flag adds line numbers, so you can jump straight to the problem. Here it found two errors in a server log. grep is case-sensitive by default. Add -i to ignore case.

On Windows and macOS

On Windows PowerShell, cp, mv, rm and cat all work. They are short names for the full commands. The full names are Copy-Item, Move-Item, Remove-Item and Get-Content. For searching, use Select-String. It does what grep does, and ignores case by default. On macOS, all five commands are the same as on Linux, including grep -n.

Recap

Recap. cp copies. mv moves or renames. rm deletes, with no trash can. cat reads a file, and grep finds a word inside it.

Next episode

Next episode: permissions and admin rights. You will learn who may do what, and what sudo really means. Subscribe so you do not miss it, and find written notes for every lesson at changecv.com/skills.

Common questions

Can I get a file back after rm?

Usually not. rm does not move the file to a trash folder, it removes it. Check the name before you press Enter, and be careful with rm -r, which removes a whole folder and everything in it.

How do I rename a file?

Use mv with the old name and the new name. Moving a file within the same folder is the same thing as renaming it.

Why does cp fail on a folder?

A folder has files inside it, so you have to ask for a recursive copy with cp -r. In PowerShell, Copy-Item needs -Recurse for the same reason.

Is grep case-sensitive?

Yes on Linux and macOS: ERROR and error are different. Add -i to ignore case. PowerShell Select-String ignores case by default, and -CaseSensitive turns that off.

What does grep -n do?

It puts the line number in front of every matching line, which helps you find the place in a long file.