Linux Basics · Lesson 8 · 20 min

Make, copy, move, delete

Time to actually change things. These commands work the same on every Linux distro. The only difference in this lesson is which text editor comes pre-installed.

You will learn

  • mkdir and touch to create folders and files
  • echo with > and >> to write into files, and cat to read them
  • cp, mv and rm, and why rm deserves respect

Create things

Same on both
mkdir projects                 # make a folder
mkdir -p school/2026/math      # make a whole path at once (-p = parents)
touch todo.txt                 # make an empty file

Write and read text

echo prints text. Add an arrow to send that text into a file instead of the screen:

Same on both
echo "Buy snacks" > todo.txt       # >  = REPLACE the file's contents
echo "Learn Linux" >> todo.txt     # >> = ADD to the end
cat todo.txt                      # print the whole file
Buy snacks
Learn Linux
Careful

One > wipes out whatever was in the file. Two >> add to it. Mixing them up is a classic way to lose your notes.

For long files, less lets you scroll (press q to quit). head shows the first 10 lines and tail the last 10.

Copy, move, rename

Same on both
cp todo.txt todo-backup.txt      # copy a file
cp -r projects projects-backup   # copy a folder (-r = recursive: everything inside)
mv todo.txt projects/            # move into a folder
mv draft.txt final.txt           # "move" to a new name = rename!

Linux has no separate rename command. You just mv the file to its new name.

Delete (read this twice)

Same on both
rm old.txt            # delete a file
rmdir empty-folder    # delete an EMPTY folder (safe)
rm -r old-folder      # delete a folder and EVERYTHING in it
rm -i file.txt        # ask "are you sure?" first
There is no Recycle Bin

rm doesn't move files to a trash can. They're just gone. rm -rf (recursive + force) deletes whole folders without asking a single question. Before you press Enter on any rm, read the path again. Real admins have wiped production servers with a stray space: rm -rf / home/old instead of rm -rf /home/old.

Text editors

Sooner or later you'll want to edit a file properly. Here the families differ:

Rocky / RHEL
sudo dnf install nano
nano notes.txt

A minimal Rocky server ships with only vi. You have to install nano yourself.

Ubuntu / Debian
nano notes.txt

nano is already installed. vi/vim is there too.

In nano, the shortcuts are listed at the bottom of the screen (^ means Ctrl): Ctrl+O saves and Ctrl+X exits. If you end up in vi by accident, press Esc, type :q! and press Enter to escape. Every Linux user gets trapped in vi once. 😅

Try it

The playground can't open full-screen editors, so use echo with > to write files.

Quick check

1. How do you rename draft.txt to essay.txt?

2. notes.txt has 10 lines. You run echo hi > notes.txt. How many lines does it have now?

3. You need nano on a fresh Rocky server. What do you type?

Finished the missions and the quiz? Mark it done to track your progress.