Skip to content
Programming contents

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:

Linux · Bash
touch notes.txt

On Windows, ni (from New-Item). touch doesn't exist in PowerShell:

Windows · 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:

Terminal
echo "Buy bread" > notes.txt
cat notes.txt
Terminal
Buy bread

If the file already had something, > replaces it.

Copying, moving and deleting

CommandWhat it does
cp notes.txt copy.txtCopies
mv copy.txt old.txtRenames
mv notes.txt my-gameMoves to another folder
rm old.txtDeletes a file
rm -r folderDeletes 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

Exercise

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
Linux · Bash
touch ideas.txt
cp ideas.txt copy.txt
rm copy.txt
ls
Terminal
ideas.txt
Windows · PowerShell
ni ideas.txt
cp ideas.txt copy.txt
rm copy.txt
ls
Terminal
    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: touch on Linux, ni on Windows.
  • echo "…" > file writes; cat reads.
  • cp copies, mv moves or renames, rm deletes. The same on both.
  • rm skips the recycle bin.