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
mkdirandtouchto create folders and filesechowith>and>>to write into files, andcatto read themcp,mvandrm, and whyrmdeserves respect
Create things
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:
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
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
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)
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
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:
sudo dnf install nano nano notes.txt
A minimal Rocky server ships with only vi. You have to install nano yourself.
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?
✓ Yes. Moving a file to a new name renames it. cp would leave you with two files.
2. notes.txt has 10 lines. You run echo hi > notes.txt. How many lines does it have now?
✓ Ouch, just 1. A single > replaces the whole file. Use >> to add a line instead.
3. You need nano on a fresh Rocky server. What do you type?
✓ Rocky uses dnf, and minimal installs don't include nano. Lesson 11 covers installing software properly.