Skip to content
Menu

RHSA: Managing Files

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:).

DirectoryPurposeRHCSA Relevance
/The root of the entire filesystem.The starting point for all absolute paths.
/etcContains system-wide configuration files.Critical for configuring services like sshd or httpd.
/homeContains user home directories (e.g., /home/john).Essential for user management and data storage.
/varContains variable data like logs, databases, and websites.Log files in /var/log are crucial for troubleshooting.
/tmpTemporary 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.

CommandPurposeExample
pwdPrint Working Directory – shows where you are.pwd → /home/john
lsList directory contents.ls -l (detailed list), ls -a (show hidden files)
cdChange Directory.cd /etccd .. (up one level), cd or cd ~ (go home)
treeDisplay 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.

WildcardPurposeExample
*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.txtfile2.txtfile3.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.

OperatorPurposeExample
>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

FeatureHard LinkSoft/Symbolic Link
Points to:The inode directly.The filename/path.
Behavior:An additional name for the exact same file.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_nameln -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] file
    • whou (user/owner), g (group), o (others), a (all)
    • operator+ (add), - (remove), = (set exactly)
    • permissionsr (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

CommandPurposeExample
findPowerful search based on name, size, type, etc.find /etc -name "httpd.conf"
find /home -type f -size +10M
locateVery fast search using a pre-built database.locate sshd_config
whichShows the full path of a shell command.which systemctl
typeShows 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 → creates file.tar.gz
  • bzip2: bzip2 file.tar → creates file.tar.bz2
  • xz: xz file.tar → creates file.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

CommandPurposeExample
catView entire file content.cat /etc/passwd
headView first lines of a file (default: 10).head -5 /etc/passwd
tailView last lines of a file (default: 10).tail -5 /etc/passwd
wcWord count (lines, words, characters).wc -l /etc/passwd (count users)
sortSort lines of a file.sort /etc/passwd
uniqReport or omit repeated lines (use on sorted data).sort file.txt | uniq
diffCompare two files line-by-line.diff file1.txt file2.txt
cmpCompare two files byte-by-byte.cmp file1.txt file2.txt
cutExtract columns/fields from text.cut -d: -f1 /etc/passwd (get usernames)
grepSearch for text patterns.grep "root" /etc/passwd

Summary: The RHCSA Workflow

  1. Navigate: Use pwdlscd to move around.
  2. Locate: Use find or locate to find files.
  3. Inspect: Use catheadtailless to view contents.
  4. Analyze: Use grepcutsortwc to process information.
  5. Manage: Use chmod and chown to control access.
  6. Backup: Use tar to create archives for safe-keeping.

Conclusion: Mastery of the filesystem and these core utilitie

Leave a Reply

Your email address will not be published. Required fields are marked *