Day 4 Practice Exam Paper: Links, Documentation, Vim, and Variables¶
Note: This is a practice paper written in the style of a hands-on, performance-based exam. It is not a real exam, does not reproduce real exam questions, and its point values are for self-assessment only. Confirm the actual exam format and objectives on Red Hat's official EX200 page.
Exam Information¶
| Item | Detail |
|---|---|
| Suggested time | 75 minutes |
| Total points | 67 (self-assessed) |
| Environment | Your own RHEL 9 or 10 practice VM |
| Account | root (for example from sudo -i) |
| Resources allowed | Manual pages (man) only |
| Prerequisite | An existing regular user, written <user> below |
Instructions¶
- Work only on a private practice VM that you can reset. Take a snapshot first.
- Perform every task from the command line. Tasks 12 and 13 must be done in Vim.
- Grading is on the end result. Where a task says persistent, it must still be in place after a new login or reboot.
- Files go in
/root/exam4unless stated. - Do not delete anything outside
/root/exam4(the only other changes are to/root/.bashrcand/etc/profile.d/, as the tasks state). - Do not disable SELinux or the firewall.
- Back up
/root/.bashrcbefore changing it. Never add commands that print output to it.
Tasks¶
Task 1 (2 points)
Create the directory /root/exam4.
Task 2 (3 points)
Create /root/exam4/data/original.txt containing exactly three lines: alpha, beta, gamma.
Task 3 (3 points)
Create a hard link named /root/exam4/data/hard1 to original.txt.
Task 4 (3 points)
Create a soft link named /root/exam4/data/soft1 to original.txt. The link target must be an absolute path.
Task 5 (3 points)
Save a long listing that includes inode numbers for original.txt, hard1, and soft1 (in that order) to /root/exam4/inodes.txt.
Task 6 (3 points)
Add the line delta to the end of the data through the hard link hard1. The three original lines must remain. The change must be visible when reading original.txt.
Task 7 (4 points)
Create the directory /root/exam4/dirs/real. In /root/exam4/dirs, create a soft link named shortcut that points to real using a relative target. Entering /root/exam4/dirs/shortcut must work.
Task 8 (3 points)
Save a long listing of /root/exam4/dirs (its contents, showing where each link points) to /root/exam4/dirs-listing.txt.
Task 9 (5 points)
Delete /root/exam4/data/original.txt. Then:
- Save the contents of
hard1to/root/exam4/survive.txt. - Save a long listing of
soft1(the link itself) to/root/exam4/broken.txt.
Task 10 (3 points)
Using a keyword search of the manual page descriptions, save the entries that match the keyword useradd to /root/exam4/mankeyword.txt. (If the search returns nothing, rebuild the manual index first.)
Task 11 (3 points)
Save the one-line description of the ls command, as given by the system, to /root/exam4/whatis-ls.txt.
Task 12 (6 points)
Create /root/exam4/edit.txt containing the numbers 1 to 5, one per line. Then, using Vim, change the file so that it contains exactly these lines in this order:
1
inserted
2
4
5
Task 13 (4 points)
Using Vim, change /root/exam4/edit.txt so that the last line is duplicated. The file must now end with 5 twice.
Task 14 (3 points)
In your current shell, create a variable named course with the value RHCSA (do not export it). Save its value to /root/exam4/var1.txt.
Task 15 (5 points)
Make a variable named lab_owner with the value student1 available in every new shell for the root user (persistent). Load it into your current shell, and save its value to /root/exam4/var2.txt.
Task 16 (5 points)
Make an exported environment variable LAB_ENV with the value practice available to all users at login (persistent), using the system-wide login drop-in mechanism. Verify it as <user> using a login shell, and save the value that <user> sees to /root/exam4/var3.txt.
Task 17 (3 points)
Show that a child shell does not see the unexported variable course. Save the output of a child shell that prints the value of course inside square brackets (for example [value]) to /root/exam4/child.txt.
Task 18 (2 points)
Save the absolute path of the root user's home directory to /root/exam4/home.txt using a variable (do not type the path by hand).
Task 19 (4 points)
Using only relative paths, create the directory /root/exam4/rel/one/two while your current directory is /root/exam4/data. Then, from inside two, save the output that shows your current absolute location to /root/exam4/rel.txt.
Self-Check Before You Finish¶
- [ ]
hard1andoriginal.txt(before deletion) shared an inode, andsoft1had its own. - [ ]
survive.txtcontains four lines, andbroken.txtshows a link whose target is gone. - [ ]
edit.txtends with5twice and containsinsertedas its second line. - [ ] A new login shell for
rootprintsstudent1forlab_owner. - [ ] A login shell for
<user>printspracticeforLAB_ENV. - [ ]
child.txtshows an empty value inside the brackets. - [ ] You backed up
/root/.bashrcand did not add output-producing commands to it.
Answer Key and Marking Guide¶
Try the paper first. Output varies by system, so compare meaning, not exact text. All commands assume a root shell.
Task 1
mkdir /root/exam4
Task 2
mkdir -p /root/exam4/data
printf "alpha\nbeta\ngamma\n" > /root/exam4/data/original.txt
Task 3
ln /root/exam4/data/original.txt /root/exam4/data/hard1
Task 4
ln -s /root/exam4/data/original.txt /root/exam4/data/soft1
Task 5
ls -li /root/exam4/data/original.txt /root/exam4/data/hard1 /root/exam4/data/soft1 > /root/exam4/inodes.txt
cat /root/exam4/inodes.txt
original.txt and hard1 show the same inode and a link count of 2. soft1 shows a different inode and ->.
Task 6
echo delta >> /root/exam4/data/hard1
cat /root/exam4/data/original.txt
Expected: alpha, beta, gamma, delta.
Task 7
mkdir -p /root/exam4/dirs/real
cd /root/exam4/dirs
ln -s real shortcut
cd /root/exam4/dirs/shortcut && pwd
The relative target real is read from /root/exam4/dirs, so the link works.
Task 8
ls -l /root/exam4/dirs > /root/exam4/dirs-listing.txt
The listing shows shortcut -> real.
Task 9
rm /root/exam4/data/original.txt
cat /root/exam4/data/hard1 > /root/exam4/survive.txt
ls -l /root/exam4/data/soft1 > /root/exam4/broken.txt
survive.txt has the four lines. soft1 is now dangling, so cat /root/exam4/data/soft1 would fail.
Warning: rm is not reversible. Delete only the single file named in the task.
Task 10
man -k useradd > /root/exam4/mankeyword.txt
If the file is empty: mandb, then repeat. The file should contain a line for the useradd page with its section and short description.
Task 11
whatis ls > /root/exam4/whatis-ls.txt
Task 12
seq 1 5 > /root/exam4/edit.txt
vim /root/exam4/edit.txt
In Vim: press o, type inserted, press Esc. The lines are now 1, inserted, 2, 3, 4, 5. Press j twice to reach the line 3 (the cursor is on inserted, so one j reaches 2 and another reaches 3), then press dd. Save and quit with :wq.
cat /root/exam4/edit.txt
Expected: 1, inserted, 2, 4, 5.
Task 13
vim /root/exam4/edit.txt
In Vim: press G to go to the last line, press yy to copy it, press p to paste it below, and save with :wq.
tail -n 2 /root/exam4/edit.txt
Expected: 5 and 5.
Task 14
course="RHCSA"
echo $course > /root/exam4/var1.txt
Task 15
cp /root/.bashrc /root/.bashrc.bak
echo 'lab_owner=student1' >> /root/.bashrc
source /root/.bashrc
echo $lab_owner > /root/exam4/var2.txt
bash -l -c 'echo $lab_owner' # should print student1 in a fresh login shell
A plain assignment is enough here, because the task asks only that it is available in every new shell. Use export lab_owner=student1 instead if you want child programs to see it as well.
Task 16
echo 'export LAB_ENV=practice' > /etc/profile.d/lab-env.sh
su - <user> -c 'echo $LAB_ENV' > /root/exam4/var3.txt
cat /root/exam4/var3.txt
Expected: practice. Scripts in /etc/profile.d/ are read at login for all users. The single quotes stop the current shell from expanding $LAB_ENV, so <user>'s login shell evaluates it.
Task 17
bash -c 'echo "[$course]"' > /root/exam4/child.txt
cat /root/exam4/child.txt
Expected: [], because course was not exported.
Task 18
echo $HOME > /root/exam4/home.txt
Expected: /root (when you are root).
Task 19
cd /root/exam4/data
mkdir -p ../rel/one/two
cd ../rel/one/two
pwd > /root/exam4/rel.txt
cat /root/exam4/rel.txt
Expected: /root/exam4/rel/one/two.
Common mistakes
- Reversing the arguments of
ln. The first is what you link to. - Using a relative soft-link target that is wrong for the link's directory.
- Using
>instead of>>in Task 6, which loses the original lines. - Deleting the hard link
hard1instead oforiginal.txtin Task 9. - Forgetting
sourceafter editing.bashrc(Task 15). - Writing spaces around
=in a variable assignment. - Expanding
$LAB_ENVin the wrong shell by using double quotes in Task 16. - Starting to type in Vim before pressing
ioro.
Final persistence check
bash -l -c 'echo $lab_owner'
su - <user> -c 'echo $LAB_ENV'
Both should print their values. A reboot does not change the result.
Cleanup (after marking yourself)
cp /root/.bashrc.bak /root/.bashrc
unset course lab_owner
rm /etc/profile.d/lab-env.sh
rm -r /root/exam4
Remove only items you created.
Scoring (self-assessment)
| Score | Level |
|---|---|
| 60 to 67 | Excellent |
| 47 to 59 | Good. Review missed tasks |
| Below 47 | Repeat the Day 4 lab and drills |