1. Understand and Use Essential Tools
πRed Hat Certified System Administrator (RHCSA β EX200)
In Linux, managing files and directories is one of the most important skills for the RHCSA exam. Every Linux system administrator must know how to create, remove, copy, and move files and directories quickly using the command line. This is not just theory β youβll need to perform these tasks in the exam.
1. Creating Files
In Linux, you can create files in several ways:
a) Using touch
- Syntax:
touch filename
- What it does: Creates an empty file if it doesnβt exist. If it already exists, it updates the fileβs timestamp.
- Example:
touch server.log
This creates an empty file called server.log in your current directory.
b) Using echo
- Syntax:
echo "Some text" > filename
- What it does: Creates a file and writes text into it.
- Example:
echo "Server started at 10:00 AM" > server.log
Now, server.log contains that line.
c) Using cat
- Syntax:
cat > filename
- What it does: Lets you type multiple lines into a file until you press Ctrl+D.
- Example:
cat > users.txt
john
mary
alice
Ctrl+D
Now, users.txt has three lines.
2. Creating Directories
Directories are containers for files.
a) Using mkdir
- Syntax:
mkdir directory_name
- Example:
mkdir backups
Creates a directory called backups.
b) Creating multiple directories
- Syntax:
mkdir dir1 dir2 dir3
- Example:
mkdir logs temp scripts
Creates logs, temp, and scripts directories at once.
c) Creating nested directories
- Syntax:
mkdir -p parent/child/grandchild
- Example:
mkdir -p /home/itteam/projects/2026
Creates projects inside /home/itteam and a subdirectory 2026 in it, even if projects doesnβt exist yet.
3. Deleting Files
Linux provides the rm command to delete files:
a) Delete a single file
rm filename
- Example:
rm old_server.log
Removes the old_server.log file.
b) Delete multiple files
rm file1 file2 file3
- Example:
rm temp1.txt temp2.txt temp3.txt
Removes all three files at once.
c) Delete files interactively
- Option:
-iasks before deleting each file.
rm -i temp.txt
β οΈ Warning: Thereβs no βRecycle Binβ in Linux. Once deleted with rm, the file is gone unless you have a backup.
4. Deleting Directories
Use rmdir or rm -r:
a) Using rmdir
- Syntax:
rmdir directory_name
- Works only if the directory is empty.
- Example:
rmdir old_backups
b) Using rm -r
- Syntax:
rm -r directory_name
- Deletes the directory and everything inside it.
- Example:
rm -r temp
c) Safe deletion with confirmation
rm -ri temp
Asks before deleting each file or subdirectory.
5. Copying Files
The cp command copies files or directories.
a) Copy a single file
- Syntax:
cp source_file destination_file
- Example:
cp server.log server_backup.log
Creates a copy of server.log called server_backup.log.
b) Copy to a directory
- Syntax:
cp file_name directory_name/
- Example:
cp server.log backups/
Copies server.log into the backups directory.
c) Copy multiple files
cp file1 file2 file3 destination_directory/
d) Copy directories
- Must use
-rfor recursive copying.
cp -r source_directory destination_directory
- Example:
cp -r projects/ /home/itteam/backups/
Copies the entire projects folder, including all files and subfolders, to backups.
6. Moving and Renaming Files
The mv command is used for moving or renaming files/directories.
a) Move a file
- Syntax:
mv source_file destination_directory/
- Example:
mv server.log backups/
Moves server.log into backups.
b) Rename a file
- Syntax:
mv old_name new_name
- Example:
mv server.log server_old.log
Renames the file without moving it.
c) Move multiple files
mv file1 file2 file3 destination_directory/
d) Move directories
- Works the same as files:
mv old_directory/ new_location/
7. Useful Options for File and Directory Management
| Command | Option | Purpose |
|---|---|---|
rm | -i | Ask before deleting |
rm | -f | Force deletion, ignore warnings |
rm | -r | Recursive, for directories |
cp | -i | Ask before overwriting files |
cp | -r | Copy directories recursively |
mv | -i | Ask before overwriting |
mkdir | -p | Create parent directories if not exist |
8. Exam Tips
- Remember
-rfor directories: In Linux, you cannot copy or delete a folder withcporrmwithout-r. - Interactive mode is your friend: Use
-iin the exam to avoid mistakes. - Files vs Directories: Commands like
rmandmvwork on both, but directory operations often need-r. - Practice paths: Know absolute vs relative paths:
- Absolute:
/home/itteam/backups/file.txt - Relative:
../backups/file.txt
- Absolute:
- Do not rely on GUI: The RHCSA exam is command-line only.
9. Quick Command Reference
| Task | Command |
|---|---|
| Create empty file | touch file.txt |
| Create file with content | echo "text" > file.txt |
| Create directory | mkdir dir |
| Create nested directories | mkdir -p parent/child |
| Delete file | rm file.txt |
| Delete empty directory | rmdir dir |
| Delete directory and contents | rm -r dir |
| Copy file | cp file.txt backup.txt |
| Copy file to directory | cp file.txt /backup/ |
| Copy directory | cp -r dir /backup/ |
| Move file | mv file.txt /backup/ |
| Rename file | mv old.txt new.txt |
This covers everything you need to handle files and directories for the RHCSA exam. If you can confidently create, delete, copy, and move files and directories with all the options mentioned above, you will be fully prepared for this section.
