Study guide
4.1 Create, Delete, Copy, and Move Files and Directories
Red Hat Certified System Administrator RHCSA
Track your progress as you read
Finished sections get a check mark.
1 Introduction & Exam Overview
1.1 Current Exam Facts 1.2 Lab Setup & Performance-Based Study Strategy
2 Essential Tools: Shell, Redirection & Text Analysis
2.1 Shell Prompt and Command Syntax 2.2 Input-Output Redirection and Pipes 2.3 grep and Regular Expressions for Text Analysis
3 Essential Tools: Remote Access, Users & Text Editing
3.1 Access Remote Systems Using SSH 3.2 Log In and Switch Users in Multiuser Targets 3.3 Create and Edit Text Files
4 Essential Tools: Files, Links & Archives
4.1 Create, Delete, Copy, and Move Files and Directories 4.2 Hard and Soft Links 4.3 Archive and Compress with tar, gzip, and bzip2
5 Essential Tools: Permissions & System Documentation
5.1 List, Set, and Change Standard ugo/rwx Permissions 5.2 System Documentation: man, info, and /usr/share/doc
6 Manage Software: RPM and Flatpak
6.1 Configure Access to RPM Repositories 6.2 Install and Remove RPM Software Packages 6.3 Configure Access to Flatpak Repositories 6.4 Install and Remove Flatpak Software Packages
7 Create Simple Shell Scripts
7.1 Conditional Execution: if, test, and [] 7.2 Looping Constructs for Files and Input 7.3 Process Script Inputs ($1, $2, and Beyond) 7.4 Process Shell Command Output in Scripts
8 Operate Running Systems: Boot and Recovery
8.1 Boot, Reboot, and Shut Down a System Normally 8.2 Boot Systems into Different Targets Manually 8.3 Interrupt the Boot Process to Gain Access
9 Operate Running Systems: Processes and Tuning
9.1 Identify and Kill CPU/Memory Intensive Processes 9.2 Adjust Process Scheduling 9.3 Manage Tuning Profiles
10 Operate Running Systems: Logs, Services & File Transfer
10.1 Locate and Interpret System Log Files and Journals 10.2 Preserve System Journals 10.3 Start, Stop, and Check Status of Network Services 10.4 Securely Transfer Files Between Systems
11 Configure Local Storage: Partitions and LVM
11.1 List, Create, and Delete Partitions on GPT Disks 11.2 Create and Remove Physical Volumes 11.3 Assign Physical Volumes to Volume Groups 11.4 Create and Delete Logical Volumes
12 Configure Local Storage: Mounting and Expansion
12.1 Mount File Systems at Boot by UUID or Label 12.2 Add Partitions, Logical Volumes, and Swap Non-Destructively
13 Create and Configure File Systems: Local FS and Permissions
13.1 Create, Mount, and Use VFAT, ext4, and XFS File Systems 13.2 Extend Existing Logical Volumes 13.3 Diagnose and Correct File Permission Problems
14 Create and Configure File Systems: NFS and autofs
14.1 Mount and Unmount Network File Systems Using NFS 14.2 Configure autofs
15 Deploy and Maintain: Scheduling, Services & Targets
15.1 Schedule Tasks with at, cron, and systemd Timers 15.2 Start, Stop, and Enable Services at Boot 15.3 Configure Systems to Boot into a Specific Target
16 Deploy and Maintain: Time, Software Updates & Bootloader
16.1 Configure Time Service Clients 16.2 Install and Update Software from CDN, Remote Repos, and Local Files 16.3 Modify the System Bootloader
17 Manage Basic Networking
17.1 Configure IPv4 and IPv6 Addresses 17.2 Configure Hostname Resolution 17.3 Configure Network Services to Start Automatically at Boot 17.4 Restrict Network Access Using firewalld and firewall-cmd
18 Manage Users and Groups
18.1 Create, Delete, and Modify Local User Accounts 18.2 Change Passwords and Adjust Password Aging 18.3 Create, Delete, and Modify Local Groups and Memberships 18.4 Configure Privileged Access
19 Manage Security: Firewall, umask & SSH Keys
19.1 Configure Firewall Settings with firewall-cmd and firewalld 19.2 Manage Default File Permissions 19.3 Configure Key-Based Authentication for SSH
20 Manage Security: SELinux Modes and Contexts
20.1 Set Enforcing and Permissive Modes for SELinux 20.2 List and Identify SELinux File and Process Contexts 20.3 Restore Default File Contexts
21 Manage Security: SELinux Ports and Booleans
21.1 Manage SELinux Port Labels 21.2 Use Boolean Settings to Modify SELinux Settings
4.1 Create, Delete, Copy, and Move Files and Directories
Key Takeaways Explain This Topic AI
mkdir -p creates parent path components as needed; rmdir removes only empty directories while rm -r removes trees recursively.
cp copies; use cp -a (or -dR --preserve=all) when you must keep permissions, ownership, timestamps, and links for admin backups.
mv renames or relocates files and directories on the same or different filesystems; it does not leave a second copy behind.
rm removes directory entries; rm -r (and carefully rm -rf) deletes directory trees—always confirm paths with pwd and ls before destructive flags.
Touch creates empty files or updates timestamps; combine mkdir -p, cp -a, mv, and rm into deliberate workflows so exam artifacts end in the correct path with correct attributes.
Last updated: August 2026
4.1 Create, Delete, Copy, and Move Files and Directories
Quick Answer: Create directories with mkdir / mkdir -p , empty files with touch , copy with cp (use cp -a to preserve attributes), move or rename with mv , and remove with rm / rm -r . Always verify identity, path, and attributes with pwd , ls -l , and stat before and after changes.
The EX200 essential-tools objective to create, delete, copy, and move files and directories is pure day-to-day Linux administration. Almost every later task—deploying configs under /etc , staging content under /var , or assembling a home-directory lab—depends on getting paths, recursion, and attributes right the first time.
Mental Model: Directory Entries and Trees
A file is data identified by an inode (metadata: size, permissions, timestamps, ownership). A directory is a special file that maps names to inodes. When you cp , mv , or rm , you manipulate names and sometimes data:
- Action Typical effect
- touch name Create empty file or update timestamps
- mkdir name Create a directory entry
- cp src dest New name and usually new inode/data copy
- mv src dest Change name/location (same inode if same filesystem)
- rm name Remove directory entry; data freed when last link is gone
Hard and soft links (next section) build on this inode model. For this section, treat every exam path as something you must create correctly, place correctly, and not destroy accidentally .
- Creating Directories: mkdir mkdir project
- mkdir -p /home/student/labs/ex200/files
- mkdir -m 755 /srv/www
- mkdir dir1 dir2 dir3
- Option Purpose
- p Create parent directories as needed; no error if the path already exists
- m mode Set mode at creation (subject to umask interaction—verify with ls -ld )
- multiple names Create several directories in one command
Why -p matters on the exam: Tasks often specify deep paths ( /home/bob/projects/app/config ). Without -p , mkdir fails if a parent is missing. With -p , one command builds the whole chain. mkdir -p is also safe when re-running a recipe: existing directories are left alone rather than failing.
- Verify: ls -ld /home/student/labs/ex200/files
- namei -l /home/student/labs/ex200/files # optional path walk
- Creating Empty Files and Updating Timestamps: touch touch notes.txt
- touch /tmp/a /tmp/b /tmp/c
- touch -t 202608051200.00 stamped.txt # set explicit timestamp when required
touch creates a zero-length file if the name does not exist, or updates access/modification times if it does. Exam tasks often say “create an empty file named X in directory Y”— touch Y/X after mkdir -p Y is the standard pattern.
- Other quick creation methods (already familiar from editing/redirection chapters): echo 'content' > file.txt
- cat > file.txt <<'EOF'
- line1
- line2
- EOF
Prefer touch when content is not required yet; prefer redirection or an editor when the file must contain specific text.
- Copying: cp cp source dest
- cp file1 file2 file3 /path/to/dir/
- cp -r sourcedir destdir
- cp -a sourcedir destdir
- Essential options
- Option Purpose
- r or -R Recursive copy of directories
- a Archive mode: recursive + preserve attributes (roughly -dR --preserve=all )
- p Preserve mode, ownership (if permitted), and timestamps
- v Verbose—show what is copied
- i Interactive prompt before overwrite
- n No clobber (do not overwrite)
- d Preserve symlinks as symlinks (do not follow)
- L Always follow symlinks (copy the target content)
- When to use cp -a
Exam trap: A plain cp -r copies content but may not fully preserve ownership, permissions, timestamps, or special file types the way an administrator backup should. Graders (and real restore drills) often care about:
- Permission bits and ownership
- Timestamps
- Symlinks remaining symlinks
- Extended attributes where relevant
Prefer cp -a when the task says “preserve attributes,” “exact copy,” “backup,” or when copying system trees you will compare with ls -l / stat later. cp -a /etc/ssh /root/ssh-backup
- ls -l /etc/ssh/sshd_config /root/ssh-backup/sshd_config
- stat /etc/ssh/sshd_config /root/ssh-backup/sshd_config
If you copy as an unprivileged user into a path you own, ownership of new files is typically your UID—even when the source was root-owned. Only root (or capable processes) can create root-owned copies. Use sudo cp -a when the destination must keep original ownership under restricted paths.
Destination rules
If dest is an existing directory, sources are placed inside it with the same basenames.
If dest does not exist and you copy one file, dest becomes the new file name.
If dest does not exist and you use cp -r srcdir destdir , destdir is created as the copy of srcdir. cp report.txt /tmp/ # /tmp/report.txt
cp report.txt /tmp/report.bak # renamed copy
cp -a project /tmp/ # /tmp/project/...
- Moving and Renaming: mv mv oldname newname
- mv file1 file2 dir3 /path/to/dir/
- mv project /home/student/archive/
mv renames when source and destination are on the same filesystem (inode stays the same; only the directory entry changes). Across filesystems, mv typically copies then removes the original—behavior you notice if a huge tree move is slow or if attributes fail to transfer under restricted permissions.
- Situation Result
- mv a b and b does not exist Rename a → b
- mv a b and b is a directory Move a into b/
- mv a b and b is an existing file Overwrite b (prompt if -i or alias forces it)
Useful options: -i (interactive), -n (no clobber), -v (verbose).
Exam use cases: Rename files to match a required name, relocate a completed project into a grading path, or reorganize after creating content in the wrong directory. Unlike cp , successful mv does not leave the original path behind—do not use mv when you still need the source in place.
- Removing: rm and rmdir
- rmdir — empty directories only rmdir emptydir
- rmdir -p a/b/c # remove c, then b, then a if each becomes empty
If the directory is not empty, rmdir fails. That is a safety feature, not a bug.
- rm — files and trees rm file.txt
- rm -r directory/
- rm -rf directory/ # recursive + force (no prompts; dangerous)
- rm -i file1 file2 # prompt each
- Option Purpose
- r / -R Recursive delete of directories
- f Force; ignore nonexistent files and usually skip prompts
- i Prompt before each removal
- d Remove empty directories (like rmdir) on some implementations
Exam discipline:
pwd and ls before rm -r .
Prefer absolute paths for destructive commands on system trees.
Avoid casual rm -rf / patterns and watch trailing spaces/globs ( rm -rf $VAR/ when VAR is empty is catastrophic in scripts).
Remember that rm removes names ; if other hard links exist, data may remain under another name (next section).
Aliases on some interactive shells map rm to rm -i . On exams, know the real binary behavior and do not assume prompts will always save you—especially in scripts or bash -c .
Building a Complete Workflow
Typical multi-step task wording: “Create directory structure X; place files; copy a template preserving permissions; move the tree to Y; remove temporary files.” whoami
- mkdir -p /home/student/work/app/{bin,etc,data}
- touch /home/student/work/app/etc/app.conf
- echo 'listen=8080' > /home/student/work/app/etc/app.conf
- cp -a /usr/share/doc /home/student/work/app/data/doc-backup 2>/dev/null || true
- mv /home/student/work/app /home/student/final-app
- rm -r /home/student/work
- ls -laR /home/student/final-app
Brace expansion {bin,etc,data} creates multiple siblings under one parent—fast and accurate under time pressure. Confirm with ls -laR or targeted find .
- Preserving Attributes and Comparing Results
- After copies that must match the source: ls -l source dest
- stat source dest
- getfacl source dest # if ACLs are in play later
Timestamps, mode bits, and ownership are the first things graders or automated checks compare. If you used plain cp and the task implied an archival copy, fix with a fresh cp -a rather than manually chasing every bit.
Common Pitfalls
Forgetting -r / -a on directories — cp dir dest without recursion fails or does not copy the tree as intended.
Using cp when the task wants a rename — leaves duplicates and wrong paths.
Using mv when you still need the original — source disappears.
rm -r on the wrong path — no recycle bin on the exam.
Creating as root under a user home — ownership ends up root:root; fix with chown or recreate as the correct user.
Assuming cp -r equals cp -a — attribute and symlink handling differ; prefer -a for admin-quality trees.
Relative path mistakes — always pwd when staging multi-step file trees.
- RHEL Practice Drill mkdir -p /tmp/sg-files/{src,dst}
- echo alpha > /tmp/sg-files/src/a.txt
- cp -a /tmp/sg-files/src/a.txt /tmp/sg-files/dst/a-copy.txt
- mv /tmp/sg-files/dst/a-copy.txt /tmp/sg-files/dst/a-renamed.txt
- cp -a /tmp/sg-files/src /tmp/sg-files/dst/src-backup
- rm /tmp/sg-files/src/a.txt
- rmdir /tmp/sg-files/src || rm -r /tmp/sg-files/src
- ls -laR /tmp/sg-files
Explain to yourself after each step what still exists and what attributes ls -l shows.
Section Checkpoint
You should be able to build nested directories with mkdir -p , create files with touch or redirection, copy single files and whole trees with correct recursion, use cp -a when attributes must survive, relocate or rename with mv , and remove files or empty/non-empty directories with rmdir / rm -r without collateral damage. Those operations are the foundation for links and archives in the next sections.