Domain 1Essential ToolsCORE

File Management

Essential Linux command-line tools, file system navigation, text manipulation with grep, file permissions, tar archiving, and remote SSH access.

Domain: Domain 1: Understand and use essential tools•Updated: 2026-08-29
#CLI#Essential Tools#File Operations#Permissions#Grep#Tar#SSH

File Management

This section covers core Linux file management operations, archiving and compression with tar and gzip, soft and hard link behavior, mount options, and directory navigation utilities essential for RHCSA preparation.


Theory Questions

1. Which directory stores dynamically created temporary files cleared on reboot?

The /tmp directory is used for temporary files that do not need to persist across system reboots.

  • Command(s): ls -ld /tmp
  • Why: The system automatically cleans /tmp during boot sequences or mounts it as a temporary file system (tmpfs).
  • Gotchas: Do not confuse /tmp with /var/tmp, which preserves files across system reboots.
  • Verify: df -hT /tmp

2. Which directory is dedicated to storing system log files?

System and application logs are stored in /var/log.

  • Command(s): ls -ld /var/log
  • Why: /var/log serves as the centralized location for standard system log files and historical log archives.
  • Gotchas: Modern RHEL systems use systemd-journald binaries stored in /var/log/journal/, which are best queried using journalctl.
  • Verify: ls -l /var/log

3. How do you apply security mount options to a dedicated /home partition?

Remount the file system with nodev, nosuid, and noexec flags, and append these options to /etc/fstab.

  • Command(s): mount -o remount,nodev,nosuid,noexec /home
  • Why: nodev prevents interpreting character/block devices, nosuid ignores set-user-identifier bits, and noexec blocks binary execution on user partitions.
  • Gotchas: Omitting changes in /etc/fstab causes remounted security parameters to revert upon reboot.
  • Verify: findmnt /home

4. How do you get an accurate overview of mounted block storage devices?

Use lsblk to display physical and logical block devices in a visual tree format.

  • Command(s): lsblk
  • Why: lsblk lists physical block devices while filtering out virtual filesystems (such as proc, sysfs, and tmpfs).
  • Gotchas: df -h shows only active file system usage and omits unformatted or unmounted block devices.
  • Verify: lsblk -f

5. How do you list directory contents with the newest files listed last?

Sort by time (-t) and reverse the sort order (-r) using ls -tr.

  • Command(s): ls -tr
  • Why: -t orders files by modification timestamp (newest first), while -r reverses this order, putting the newest entries at the bottom of the terminal output.
  • Gotchas: Forgetting -r outputs the newest files at the top, which can scroll off-screen in dense directories.
  • Verify: ls -ltr

6. How do you copy all regular and hidden files from /home/$USER to the current directory?

Target the directory contents using dot notation while maintaining attributes via -a.

  • Command(s): cp -a /home/$USER/. .
  • Why: /home/$USER/. captures all contents, including hidden dotfiles (.bashrc, .config), while -a preserves ownership and permissions.
  • Gotchas: Using shell globbing wildcard * ignores hidden dotfiles. Using cp -r /home/$USER . creates a nested folder instead of copying contents directly.
  • Verify: ls -la

7. How do you rename a file from myfile to mynewfile?

Use the mv command to rename files within the same file system directory.

  • Command(s): mv myfile mynewfile
  • Why: mv changes the path reference or directory entry name of the target file.
  • Gotchas: mv will overwrite an existing destination file without prompting unless -i (interactive mode) is specified.
  • Verify: ls -l mynewfile

Hard links point directly to an existing inode on disk, whereas symbolic links point to a path string.

  • Command(s): ls -i file1 file2
  • Why: Hard links share identical inode numbers and underlying data blocks. Deleting one hard link does not erase file data until all hard links to that inode are removed.
  • Gotchas: Hard links cannot span across different file systems/partitions and cannot target directories.
  • Verify: stat file1 file2

Use ln -s specifying the target destination path followed by the link path name.

  • Command(s): ln -s /home /tmp/home_link
  • Why: -s creates a soft (symbolic) link containing a text reference pointing to /home.
  • Gotchas: Ensure target paths use absolute references to prevent broken links if the link file is moved later.
  • Verify: ls -l /tmp/home_link

10. How do you update or append files to an existing tar archive?

Use the append (-r) flag on uncompressed archives.

  • Command(s): tar -rvf archive.tar newfile
  • Why: -r appends new files to the end of an uncompressed .tar archive.
  • Gotchas: Appending files directly to compressed archives (.tar.gz, .tar.xz) is unsupported. You must unpack, add, and re-compress the archive.
  • Verify: tar -tf archive.tar

11. Which system directory contains system-wide configuration files?

System-wide administrative configuration files reside in /etc.

  • Command(s): ls -ld /etc
  • Why: /etc holds essential configuration files, startup scripts, and service parameters.
  • Gotchas: Binaries and executables should not be stored in /etc; they belong in /usr/bin or /usr/sbin.
  • Verify: ls /etc

12. How do you list directory files sorted by modification time, newest first?

Sort output using ls -t.

  • Command(s): ls -t
  • Why: The -t option sorts directory entries by modification timestamp in descending order.
  • Gotchas: Adding -r will reverse the display order, showing the oldest entries first.
  • Verify: ls -lt

13. How do you rename a file from myfile to yourfile?

Rename the filename using the mv utility.

  • Command(s): mv myfile yourfile
  • Why: mv updates the filename entry within the file system directory structure.
  • Gotchas: If yourfile already exists, mv replaces it without warning unless -i is used.
  • Verify: ls -l yourfile

14. How do you recursively delete a directory structure and all of its contents?

Execute rm -rf specifying the target directory path.

  • Command(s): rm -rf /path/to/dir
  • Why: -r processes directory trees recursively, and -f bypasses confirmation prompts and ignores non-existent files.
  • Gotchas: Double-check path parameters before pressing enter. Accidental execution on root / or system folders can destroy operating system data.
  • Verify: ls /path/to/dir

Use ln -s utilizing tilde (~) expansion to reference the home directory path.

  • Command(s): ln -s /tmp ~/tmp_link
  • Why: ~ expands dynamically to the currently logged-in user’s home path (/home/$USER).
  • Gotchas: Running this command under sudo expands ~ to /root instead of your standard user account home directory.
  • Verify: ls -l ~/tmp_link

16. How do you copy all files starting with a, b, or c from /etc to the current directory?

Match specific leading characters using square bracket globbing patterns [abc]*.

  • Command(s): cp -r /etc/[abc]* .
  • Why: [abc]* expands to match any file or folder name starting with ‘a’, ‘b’, or ‘c’. The -r flag ensures matched directories are copied recursively.
  • Gotchas: Omitting * matches only exact single-character names named a, b, or c.
  • Verify: ls -d [abc]*

Create a soft link pointing to /etc inside ~.

  • Command(s): ln -s /etc ~/etc_link
  • Why: -s creates a symbolic link pointing to the /etc target path.
  • Gotchas: Ensure the destination filename is provided to avoid link name ambiguity.
  • Verify: ls -l ~/etc_link

Remove the link using rm or unlink without appending a trailing slash.

  • Command(s): rm symlink_name (or unlink symlink_name)
  • Why: Targeting symlink_name directly unlinks the reference file without modifying the target directory contents.
  • Gotchas: Adding a trailing slash (rm symlink_name/) targets the contents inside the target directory rather than the symlink file itself.
  • Verify: ls -l symlink_name

19. How do you create a gzip-compressed tar archive of /etc and /home at /tmp/etchome.tgz?

Combine tar creation options with gzip compression using -czvf.

  • Command(s): tar -czvf /tmp/etchome.tgz /etc /home
  • Why: -c creates a new archive, -z compresses via gzip, -v shows process output, and -f names the target archive file.
  • Gotchas: The -f flag must immediately precede the archive target output path parameter.
  • Verify: tar -tzvf /tmp/etchome.tgz | head

20. How do you extract a single specific file from a compressed tar archive?

Pass the archive file and the precise internal path to tar -xzvf.

  • Command(s): tar -xzvf archive.tgz etc/passwd
  • Why: tar inspects the archive index and extracts only the specified path argument.
  • Gotchas: Archives store relative file paths stripping the leading slash (e.g., etc/passwd instead of /etc/passwd). Check internal paths first using tar -tf.
  • Verify: ls -l etc/passwd

Lab Tasks

File Management Practice

Perform end-to-end file management, archive building, link generation, and compression workflows.

Configuration Steps

# 1. Elevate session privilege to root shell
sudo -i

# 2. Build uncompressed tar archive containing /home and /etc
tar -cvf /root/essentials.tar /home /etc

# 3. Copy archive file to temporary storage directory
cp /root/essentials.tar /tmp/

# 4. Create a hard link pointing to essentials.tar at system root
ln /tmp/essentials.tar /essentials.tar

# 5. Rename hard link file reference
mv /essentials.tar /archive.tar

# 6. Create symbolic soft link in root home pointing to /archive.tar
ln -s /archive.tar /root/link.tar

# 7. Remove target archive file and verify dangling symlink behavior
rm /archive.tar
ls -l /root/link.tar

# 8. Clean up dangling soft link entry
rm /root/link.tar

# 9. Apply gzip compression to original root archive file
gzip /root/essentials.tar
  • Why:

  • tar -cvf aggregates file directories into a consolidated uncompressed stream.

  • ln generates hard links pointing to the identical inode number on the filesystem.

  • mv updates path references without altering underlying inode data.

  • rm on a target file causes symlinks pointing to its path to break (dangle).

  • gzip compresses .tar archives, replacing the source file with a .tar.gz extension.

  • Gotchas:

  • Hard links must reside on the same filesystem. If /tmp resides on an isolated mount point separate from /, ln will fail.

  • gzip removes the original uncompressed file upon successful completion unless -k (keep) is supplied.

Verification Procedures

Confirm archive creation, file size changes, and compression outputs.

# Verify resulting compressed archive file status
ls -lh /root/essentials.tar.gz

# Inspect contents of the compressed tar file
tar -tzvf /root/essentials.tar.gz | head