Foundations Module 4 · Command Line Basics

Essential Commands

Last reviewed

Beginner

What you'll learn

~18 min
  • Recognise cat, cp, mv, and rm when an AI agent proposes or runs them
  • Tell a harmless command (reading, copying) from one that changes or removes files
  • Check before a delete: rm has no undo and no Recycle Bin
  • Read a short list of commands an agent ran and say what changed

By the end of this lesson, you will recognise the four file commands an AI agent uses most (cat, cp, mv, rm) when it shows them to you or runs them, and you will know which one deserves a second look. You already have the four survival commands from the last lesson (pwd, ls, mkdir, cd). You won’t need to type these four new ones often yourself; the point is to read them.

ℹSame names on every system

PowerShell understands cat, cp, mv and rm out of the box, so on Windows, macOS and Linux an agent’s file commands look much the same. Two differences to know: options such as rm -rf are Bash/Zsh spelling (PowerShell writes them differently), and touch, a Bash/Zsh command that makes an empty file, has no PowerShell equivalent by that name.

Why read commands at all?

When an AI agent works in your project folder, it does much of its work by running terminal commands. Every command it runs appears in the session. Whether it asks you first or goes straight ahead depends on how you started the tool (Module 6 covers that choice). Either way, a glance at the commands tells you what just happened to your files.

The mental model: a desk with drawers

Think of your project folder as a desk:

  • cat = picking up a sheet and reading it (nothing changes)
  • cp = photocopying a sheet (the original stays)
  • mv = moving a sheet to a different drawer, or writing a new label on it
  • rm = shredding a sheet (no recycling bin, no undo)

The four commands to recognise

CommandWhat the agent is doingChanges your files?Worth a second look?
cat notes.txtReading a file’s contentsNoRarely
cp a.txt b.txtCopying a file (Copy)Adds a file, may overwrite oneIf the destination already exists
mv old.txt new.txtMoving or renaming (Move)YesIf the destination already exists
rm old.txtDeleting (Remove)Yes, permanentlyAlways

Try it in your own terminal

Open your terminal and move into your ai-class folder, the one your agent has used since Lesson 1.2:

Terminal window
cd ~/ai-class

(In PowerShell, use cd $HOME\ai-class.) Run pwd and check that the path ends in ai-class. Now start your installed agent in this same folder (type your start line from Lesson 1.2 in this terminal, or open a desktop app session on ai-class), and ask:

Create a file called sample.txt that says “Hello from my agent”, then show me the command you ran.

Your terminal and your agent now point at the exact same folder, so the file the agent makes is the one you check. If you don’t have an agent open yet, you can make the same file yourself:

Terminal window
echo "Hello from my agent" > sample.txt

Then check it in your own terminal, not through the agent (in a terminal CLI, leave the agent first with /exit, or open a second terminal and cd ~/ai-class there):

Terminal window
ls
cat sample.txt

How to check it worked: ls lists sample.txt, and cat sample.txt prints Hello from my agent. Nothing else changes, because both commands only read.

Keep sample.txt around. The sections below explain what each command does when you see an agent run it.

Reading: cat

Terminal window
cat notes.txt

cat prints a file’s contents to the screen. Agents run it constantly to look at a file before changing it. It never changes anything, so it’s the one you can always let through.

🧬In Your Field: Biotechclick to expand

cat is particularly useful for quickly checking data files before processing them. For example, before running an analysis script on a CSV file, you might run cat sample-data.csv to verify the headers and first few rows look right. For larger files, there are commands like head (shows the first 10 lines) and tail (shows the last 10 lines) — but cat is fine for quick checks on smaller files.

Copying: cp

Terminal window
cp original.txt backup.txt

This makes a copy of original.txt named backup.txt. The original stays untouched, just like photocopying a document. Agents often do this to keep a backup before editing something.

Terminal window
cp -r my-project my-project-backup

The -r (“recursive”) means “the folder and everything inside it”. When you see cp -r, the agent is copying a whole folder.

Moving and renaming: mv

mv both moves and renames. The pattern is always mv from to:

Terminal window
mv notes.txt documents/notes.txt

Moves notes.txt into the documents folder.

Terminal window
mv old-name.txt new-name.txt

Renames a file in place.

A helpful way to remember: mv is like cut-and-paste, while cp is like copy-and-paste.

⚠cp and mv can overwrite

In Bash and Zsh, cp and mv replace a file that already exists at the destination without asking. If an agent copies or moves onto a name you recognise, check that you didn’t need the old one.

Deleting: rm

Terminal window
rm notes.txt

This permanently deletes notes.txt. There is no Trash, no Recycle Bin, and no undo, on Windows, macOS or Linux.

Terminal window
rm -r my-folder

The -r flag deletes a folder and everything inside it. You may also see rm -rf, Bash/Zsh shorthand for “recursive, and don’t ask”.

⚠rm is the one to stop and read

When an agent proposes rm, read the path before you let it through. Is that the file or folder you expect? Is it inside your project folder? If you’re not sure, ask the agent in plain English what it is deleting and why, or ask it to move the files to an archive folder instead.

🏛️In Your Field: Government Devclick to expand

In government environments, data retention policies often require that files be preserved for specific periods. Be especially careful with rm on shared servers — deleted files cannot be recovered without backups, and some environments don’t have automated backups for user directories. When in doubt, mv files to an archive folder instead of deleting them. You can always clean up the archive later after confirming nothing important is inside.

Worked example: reading what an agent ran

Say you asked an agent to tidy up a small website project. Afterwards, the session shows it ran these commands:

Terminal window
cat index.html
cp style.css style-backup.css
mv draft-notes.txt notes.txt
mkdir images
mv logo.png images/logo.png
rm temp-output.txt

Reading them top to bottom:

  1. cat index.html: it looked at the page. Nothing changed.
  2. cp style.css style-backup.css: it saved a backup of the stylesheet before editing it.
  3. mv draft-notes.txt notes.txt: it renamed the notes file.
  4. mkdir images: it made a new images folder.
  5. mv logo.png images/logo.png: it moved the logo into that folder.
  6. rm temp-output.txt: it deleted a temporary file. This is the only line that removed anything, so it’s the one to check: was temp-output.txt really disposable?

Six lines, and you know exactly what happened to your folder. If anything looks wrong, say so in plain English and the agent can put it right (except for the deleted file, which is why rm gets the extra look).

Practice challenge

Try this in your own terminal, inside ai-class (it uses sample.txt from earlier plus a documents folder you make now), so each command is familiar when an agent uses it:

  1. Set up: mkdir documents, then cp sample.txt documents/report.txt
  2. Read a file: cat documents/report.txt
  3. Make a backup: cp documents/report.txt documents/report-backup.txt
  4. Check both exist: ls documents
  5. Rename the backup: mv documents/report-backup.txt documents/report-old.txt
  6. Look before you delete: ls documents
  7. Delete it: rm documents/report-old.txt, then ls documents to confirm it’s gone
📊In Your Field: MIS / Businessclick to expand

MIS professionals often keep a standard folder structure for each quarter’s analysis, with folders such as raw-data, cleaned-data and reports. Ask an AI agent to set one up and you’ll see a mkdir line for each folder in the session. Reading those lines, then running ls, tells you exactly what it built.

KNOWLEDGE CHECK

An agent ran `mv report.txt archive/report.txt`. What happened?

KNOWLEDGE CHECK

An agent shows you these commands. Which one deserves a careful look before it runs?

KNOWLEDGE CHECK

You want an agent to delete a folder called 'old-data' and everything inside it. Which command should you expect to see?

🔧

When Things Go Wrong

Use the Symptom → Evidence → Request pattern: describe what you see, paste the error, then ask for a fix.

Symptom
A command fails with 'Permission denied'
Evidence
cp: cannot create regular file 'config.txt': Permission denied
What to ask the AI
"You (or the agent) are probably in a system folder where regular users can't write. Run pwd to check; your work belongs in your home folder or a project folder inside it. Run cd ~ to go home, then cd into your project."
Symptom
rm says 'Is a directory'
Evidence
rm: cannot remove 'my-folder': Is a directory
What to ask the AI
"rm on its own only deletes files. Deleting a folder takes rm -r. Before using it, run ls my-folder to see what's inside."
Symptom
A file ended up with a typo in its name
Evidence
The agent saved importnat.txt instead of important.txt
What to ask the AI
"Ask the agent to rename it, or run mv importnat.txt important.txt yourself. mv is the rename tool."
Symptom
touch isn't recognised on Windows
Evidence
touch : The term 'touch' is not recognized as the name of a cmdlet, function, script file, or operable program.
What to ask the AI
"touch is a Bash/Zsh command and PowerShell has none by that name. You rarely need it: ask the agent to create the file for you."
Symptom
cp or mv says 'No such file or directory'
Evidence
cp: cannot stat 'data.csv': No such file or directory
What to ask the AI
"The source file doesn't exist at that path. Run ls to see what's actually in your current folder, check the spelling, and run pwd to make sure you're in the right place."

Quick reference

You seeIt meansChanges files?
cat notes.txtShow the file’s contentsNo
cp data.csv backup.csvCopy a fileAdds (or overwrites) a file
cp -r project project-bakCopy a whole folderAdds a folder
mv draft.txt final.txtRename a fileYes
mv notes.txt documents/Move a file into a folderYes
rm old-data.csvDelete a file, permanentlyYes
rm -r temp-filesDelete a folder and its contents, permanentlyYes
touch notes.txtMake an empty file (Bash/Zsh only)Adds a file

Key takeaways

  • Four file commands to recognise: cat (read), cp (copy), mv (move or rename), rm (delete).
  • cat and ls never change anything. cp and mv can overwrite. rm deletes permanently, with no undo and no Recycle Bin.
  • When an agent proposes rm, read the path before it runs. If in doubt, ask it why, or ask it to archive instead.
  • PowerShell understands cat, cp, mv and rm too; touch and rm -rf are Bash/Zsh only.
  • You type the four survival commands (pwd, ls, mkdir, cd); for everything else, you read what the agent ran and ask it in plain English.
🔍What about editing files from the terminal?click to expand

You might wonder how you edit a file from the terminal. There are terminal-based text editors like nano (beginner-friendly) and vim (powerful but steep learning curve). However, for this course, you’ll use VS Code for editing, which gives you a familiar visual editor. When you launch an AI CLI tool like Claude Code, it can create and edit files for you, so you rarely need to manually edit files in the terminal. If you ever need a quick edit on macOS, Linux or WSL, nano filename.txt opens a simple editor where you can type, save with Ctrl+O (then press Enter to confirm the filename), and exit with Ctrl+X.

What’s next

You can now open a terminal, move around, make folders, and read the file commands an agent runs. The next lesson looks at where you work: why Linux, WSL2 and macOS suit development, and how remote and cloud environments fit in, whenever you’re ready for them.

Search lessons