Lesson 2.2.2: Files
Everything you do with files in the file explorer can be done by typing, and almost always the same way on both systems.
The idea
Creating, viewing, copying, moving and deleting files. On Linux and Windows the commands are almost all the same: only the one for creating changes.
Creating a file
On Linux, touch:
touch notes.txt
On Windows, ni (from New-Item). touch doesn't exist in PowerShell:
ni notes.txt
Both create an empty file.
Writing and reading
> sends what a command writes into a file. cat shows what's inside. The same on both:
echo "Buy bread" > notes.txt
cat notes.txt
Buy bread
If the file already had something, > replaces it.
Copying, moving and deleting
| Command | What it does |
|---|---|
cp notes.txt copy.txt | Copies |
mv copy.txt old.txt | Renames |
mv notes.txt my-game | Moves to another folder |
rm old.txt | Deletes a file |
rm -r folder | Deletes a folder and everything in it |
They're written the same on Linux and Windows. Renaming is moving to another name, in the same folder.
Careful with rm
rm doesn't use the recycle bin: what you delete can't be recovered.
Online you'll see rm -rf to delete without questions. It's from Linux: in PowerShell it's an error, and there it's rm -r -Force.
Try it
In my-game, create ideas.txt, copy it as copy.txt and delete the copy. Check with ls that only ideas.txt is left.
Show the solution
touch ideas.txt
cp ideas.txt copy.txt
rm copy.txt
ls
ideas.txt
ni ideas.txt
cp ideas.txt copy.txt
rm copy.txt
ls
Directory: C:\Users\ana\projects\my-game
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/22/2026 10:20 0 ideas.txt
On Windows, ni shows its table first. Length 0: the file is empty.
Summary
- Creating an empty file:
touchon Linux,nion Windows. echo "…" > filewrites;catreads.cpcopies,mvmoves or renames,rmdeletes. The same on both.rmskips the recycle bin.