RHCSA File System and File Management Mastery
This guide consolidates the core concepts of the Linux filesystem hierarchy, file manipulation, permission management, and data processing tools that are fundamental to the RHCSA exam and real-world administration.
Part 1: Understanding the Linux Filesystem
1.1 What is a Filesystem?
Think of a filesystem as the library catalog and shelving system for your hard drive. It’s the method the operating system uses to:
- Name files.
- Store data on the disk.
- Retrieve data when needed.
Without it, the OS wouldn’t know where files are or how to access them.
1.2 The Linux Hierarchical Structure
Linux uses a single, inverted tree structure that starts from the root directory (/). This is a key difference from Windows (which uses drive letters like C:).
| Directory | Purpose | RHCSA Relevance |
|---|---|---|
/ | The root of the entire filesystem. | The starting point for all absolute paths. |
/etc | Contains system-wide configuration files. | Critical for configuring services like sshd or httpd. |
/home | Contains user home directories (e.g., /home/john). | Essential for user management and data storage. |
/var | Contains variable data like logs, databases, and websites. | Log files in /var/log are crucial for troubleshooting. |
/tmp | Temporary files that are deleted on reboot. | Understanding permissions and cleanup. |
1.3 Common Linux Filesystems
- ext4: The default, reliable, and widely-used filesystem.
- XFS: High-performance filesystem, often the default on newer RHEL installations. Excellent for large files.
Part 2: Navigating the Filesystem
These are the most basic and frequently used commands.
| Command | Purpose | Example |
|---|---|---|
pwd | Print Working Directory – shows where you are. | pwd → /home/john |
ls | List directory contents. | ls -l (detailed list), ls -a (show hidden files) |
cd | Change Directory. | cd /etc, cd .. (up one level), cd or cd ~ (go home) |
tree | Display directory structure as a tree (may require dnf install tree). | tree /etc |
Part 3: File Globbing (Wildcards)
Use wildcards to match multiple files/directories for efficient bulk operations.
| Wildcard | Purpose | Example |
|---|---|---|
* | Matches any number of characters. | ls *.conf (lists all .conf files) |
? | Matches exactly one character. | ls file?.txt (matches file1.txt, but not file10.txt) |
[ ] | Matches one character from a set. | ls file[1-3].txt (matches file1.txt, file2.txt, file3.txt) |
| { } | touch text{1..6}.txt ( created text1.txt to text6.txt) |
Part 4: Input/Output Redirection and Pipes
Control where command input comes from and where output goes.
| Operator | Purpose | Example |
|---|---|---|
> | Output Redirection (overwrites file). | ls -l /etc > etc_list.txt |
>> | Append Output (adds to end of file). | df -h >> disk_report.txt |
< | Input Redirection (reads from file). | wc -l < /etc/passwd |
| | Pipe (sends output to another command). | cat /var/log/messages | grep error |
Part 5: Core File Management Concepts
5.1 Inodes: The File’s ID Card
- An inode stores a file’s metadata (permissions, owner, size, timestamps, and disk location) but not its name.
- Each inode has a unique number.
- The filename is stored in a directory, which points to the inode.
5.2 Hard Links vs. Soft (Symbolic) Links
| Feature | Hard Link | Soft/Symbolic Link |
|---|---|---|
| Points to: | The inode directly. | The filename/path. |
| Behavior: | An additional name for the exact same file. | A shortcut to the original file. |
| If original is deleted: | File remains (link still points to inode). | Link breaks (“dangling link”). |
| Cross filesystem: | No. | Yes. |
| Command: | ln original link_name | ln -s original link_name |
- When two files point to the same inode number, it means they are hard links to the same underlying data on disk. In Unix-like file systems, a hard link creates another directory entry for the same file content, and both entries share the same inode.
Part 6: Managing Permissions and Ownership
6.1 Viewing Permissions: ls -l
Output: -rwxr-xr--. 1 john root 1234 Jul 10 10:30 myfile
-rwxr-xr--: Permissions string.john: File owner.root: File group.
Understanding the Permission String:- rwx r-x r--
- 1st char (
-): File type (-=file,d=directory,l=link). - Next 3 (
rwx): Owner (u) permissions. - Next 3 (
r-x): Group (g) permissions. - Last 3 (
r--): Others (o) permissions.
6.2 Changing Permissions: chmod
- Symbolic Method:
chmod [who][operator][permissions] filewho:u(user/owner),g(group),o(others),a(all)operator:+(add),-(remove),=(set exactly)permissions:r(read),w(write),x(execute)- Example:
chmod g+w myfile(Adds write permission for the group).
6.3 Changing Ownership: chown and chgrp
- Change Owner:
chown new_owner file(e.g.,chown john myfile) - Change Owner and Group:
chown owner:group file(e.g.,chown john:wheel myfile) - Change Group Only:
chgrp new_group file(e.g.,chgrp root myfile)
Part 7: Locating Files
| Command | Purpose | Example |
|---|---|---|
find | Powerful search based on name, size, type, etc. | find /etc -name "httpd.conf"find /home -type f -size +10M |
locate | Very fast search using a pre-built database. | locate sshd_config |
which | Shows the full path of a shell command. | which systemctl |
type | Shows how a command is interpreted (alias, built-in, etc.). | type cd → cd is a shell builtin |
Part 8: Archiving and Compression
8.1 The tar Command (Tape Archive)
- Create an archive:
tar -cvf archive_name.tar /path/to/dir - Extract an archive:
tar -xvf archive_name.tar - List archive contents:
tar -tvf archive_name.tar
8.2 Compression Utilities
- gzip:
gzip file.tar→ createsfile.tar.gz - bzip2:
bzip2 file.tar→ createsfile.tar.bz2 - xz:
xz file.tar→ createsfile.tar.xz
8.3 The One-Step Shortcut (Common on RHCSA)
- Create & Compress:
tar -czvf backup.tar.gz /etc - Extract & Decompress:
tar -xzvf backup.tar.gz
Part 9: File Content Analysis Toolkit
| Command | Purpose | Example |
|---|---|---|
cat | View entire file content. | cat /etc/passwd |
head | View first lines of a file (default: 10). | head -5 /etc/passwd |
tail | View last lines of a file (default: 10). | tail -5 /etc/passwd |
wc | Word count (lines, words, characters). | wc -l /etc/passwd (count users) |
sort | Sort lines of a file. | sort /etc/passwd |
uniq | Report or omit repeated lines (use on sorted data). | sort file.txt | uniq |
diff | Compare two files line-by-line. | diff file1.txt file2.txt |
cmp | Compare two files byte-by-byte. | cmp file1.txt file2.txt |
cut | Extract columns/fields from text. | cut -d: -f1 /etc/passwd (get usernames) |
grep | Search for text patterns. | grep "root" /etc/passwd |
Summary: The RHCSA Workflow
- Navigate: Use
pwd,ls,cdto move around. - Locate: Use
findorlocateto find files. - Inspect: Use
cat,head,tail,lessto view contents. - Analyze: Use
grep,cut,sort,wcto process information. - Manage: Use
chmodandchownto control access. - Backup: Use
tarto create archives for safe-keeping.
Conclusion: Mastery of the filesystem and these core utilitie