Learn › RHCSA (EX200) › Exam Orientation + Essential Tools
cp - a hands-on Linux lab on a real virtual machine.
Everyday file management for the EX200: cp with -r for directories and -p to preserve mode, owner, and time; mv to move and rename; rm and rm -r to delete; mkdir -p for trees; and the find ... -exec cp pattern that collects a user's regular files into one directory.
The EX200 will hand you something like this: find every file under a directory that a certain user owns, and gather copies of them into one collection folder. Nothing clever. Just create, copy, move, and delete files and directories, quickly and without mistakes.
It sounds trivial. It is trivial. That is exactly why it costs people points. They hesitate over which flag copies a directory, they forget how to preserve a file's permissions, they leave a symlink where a real file was asked for. This lesson makes the moves automatic so the clock stops being your enemy.
The black boxes in this lesson are a practice terminal: a safe sandbox that checks the one command each step teaches, so you cannot break anything. On the real RHEL 10 machine at the end of the module, you run these for real, against real files.
File management is four verbs and one habit. The verbs are mkdir (make a directory), cp (copy), mv (move or rename), and rm (remove). The habit is preserving what the task tells you to preserve. Together they cover the EX200 objective "create, delete, copy, and move files and directories."
A directory is just a folder. A regular file is ordinary content on disk, as opposed to a link, which is only a pointer to another file. That distinction matters more than it looks: when a task says copy the files, it means real copies, regular files, not links pointing back at the originals. Keep that in your back pocket. We return to it at the end.
The one command that anchors this lesson is cp, and the two flags that separate a pass from a miss are -r and -p.
cp has copied files on Unix since the early 1970s, and its behavior has barely changed because it did not need to. By default it does one honest thing: read a source file, write a destination file. It refuses to touch a directory unless you tell it to, and it does not carry over the source's permissions or timestamps unless you ask. Every flag you are about to learn exists to lift one of those two safety limits on purpose.
So the mental model is simple. Bare cp is the careful default. -r lets it descend into directories. -p tells it to preserve. You reach for a flag only when the task asks for that behavior.
Start with the plainest form. cp SOURCE DEST reads the source file and writes a copy at the destination. Here you copy report.txt to a new name, report.bak, in the same directory, then list the directory to see both.
Say the command out loud before you type it: cp, the source, then the new name.
prompt: student@servera:~$ answer: cp report.txt report.bak output: hint: The verb is cp. Give it two things: the file that exists, then the name for the copy.
cp prints nothing when it succeeds. Silence is success on Unix. To confirm the copy landed, you list the directory, which is the next rep.
Run ls to see the result of that copy. Both the original and the new copy are now sitting in the directory, side by side.
prompt: student@servera:~$ answer: ls output: report.bak report.txt hint: Two letters. The command that lists directory contents.
report.bak is a full, independent copy of report.txt. Change one and the other does not move. That is what plain cp gives you: a fresh regular file, not a link back to the original. Your file listing may show them in a different order or alongside other files, but the copy will be there.
Now the flag that trips people. Try to cp a directory with no flag and it refuses, printing cp: -r not specified; omitting directory. A directory is a tree, and cp will not copy a tree unless you tell it to descend. The -r flag means recursive: copy the directory and everything inside it, all the way down.
Copy the directory notes to a new directory notes-copy. Then peek inside the copy to prove the contents came along.
prompt: student@servera:~$ answer: cp -r notes notes-copy output: hint: Same cp, but a directory needs the recursive flag. It is a single letter after a dash, the one that stands for recursive.
prompt: student@servera:~$ answer: ls notes-copy output: inner.txt hint: List the contents of the directory you just copied into. ls, then the new directory name.
inner.txt inside notes-copy proves -r did its job: cp walked into the source directory, recreated the folder, and copied every file within it. Without -r you would have gotten omitting directory and no copy at all. On the exam, the instinct "directory means -r" is worth real points.
Plain cp makes a copy with a fresh timestamp and default permissions. Often that is fine. But when a task says preserve the permissions, the ownership, or the original modification time, you need -p. The -p flag means preserve: the copy keeps the source's mode (its permission bits), its owner and group, and its timestamps.
The form is cp -p SOURCE DEST. Copy report.txt to report.bak again, this time preserving its attributes.
prompt: student@servera:~$ answer: cp -p report.txt report.bak output: hint: Same source and destination as your first copy. Add the single flag that stands for preserve.
Two more forms you will meet. cp -a (archive) is -r and -p together plus link preservation, the right choice for backing up a whole directory tree intact. mkdir -p reuses the letter p for a different meaning: create parent directories as needed, and do not complain if the directory already exists. On the exam mkdir -p ~/proj/{src,docs} builds a nested tree in one line and never errors.
Two verbs remain, and both are simpler than cp.
mv moves a file or directory to a new location, and it renames in the exact same motion. mv old.txt new.txt renames; mv report.txt ~/docs/ moves. There is no -r for mv: it moves whole directory trees by default, because moving does not duplicate anything, it just changes where the entry lives.
rm removes. rm file.txt deletes a regular file. A directory needs -r again, the same recursive idea: rm -r olddir removes a directory and everything inside it. There is no recycle bin. When rm returns, the file is gone.
rm -rf deletes without asking and without erroring on missing files. It is the fastest way to clear a tree and the fastest way to end your exam early. Read the path twice before you press Enter. A stray space, as in rm -rf / home/student/junk, targets the whole system instead of one folder.
Scaffolding off. No command is shown. This is the EX200 task-6 shape in miniature.
You already created the collection directory collect. Now find every regular file under the current directory that is owned by the user student, and copy each match into collect. The right tool to find files by a predicate like owner is find: it walks the tree, tests each entry, and with -exec runs a command on every match. You want find to start at ., keep only regular files owned by student, and copy each one into collect.
Think in pieces. The type test for a regular file is -type f. The owner test is -user student. The action is -exec cp {} collect/ \;, where {} stands for each file found.
prompt: student@servera:~$ answer: find . -type f -user student -exec cp {} collect/ \; output: hint: Start with find and a dot for here. Filter to regular files with -type f, to the owner with -user student, then act with -exec cp {} collect/ and close it with an escaped semicolon.
That one line is the task-6 pattern the exam loves. find . walks the tree from where you stand. -type f throws out directories and links so only regular files survive. That is the whole point. The collection must hold real copies, not symlinks pointing back at the originals. -user student keeps only the matches that user owns. -exec cp {} collect/ \; copies each surviving file into the collection, with {} filled in per file and \; ending the -exec. Master this shape and a whole class of exam tasks becomes one line.
You earned this cheat sheet. Every row is a form you just ran or met:
The two instincts worth burning in: a directory means -r, and preserve means -p. Get those reflexive and file-management tasks stop costing you clock.
When a task says copy the files, it means regular files, not links. cp of a plain file gives you a real copy by default, and -type f in a find guarantees you never sweep a symlink into the collection. Copies must stand on their own.
The practice terminal has shown you the shape of file management: cp and its -r and -p flags, mv for move and rename, rm for delete, mkdir -p for trees, and the find ... -exec cp pattern that gathers files by owner. Every one of those you typed yourself.
Module 1, essential-tools, ends with one real RHEL 10 machine, the essential-tools capstone mission, and that is where you run these for real. The machine boots with its own files, its own owners, and its own permissions, and it hands you objectives that use exactly what you practiced across this module. One difference from here: the mission shows no commands. You read the objective, you recall the command, you type it. That recall is what the exam will ask of you.
Finish the other essential-tools lessons, then go manage real files on a real machine.
Practice File Management in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.