RHCSA study materials
RHCSA study resources

RHCSA practice questions

One question at a time. Build your RHCSA understanding.

First 50 of 199 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1Understand and use essential tools

Which shell operator redirects the standard output of a command to a file and replaces any content already in that file?

  1. 2>
  2. > Correct answer.
  3. |
  4. >>

Explanation

The single greater-than sign truncates the destination file and writes standard output into it, so previous content is lost. The append operator is >>, while 2> targets the standard error stream.

Question 2Understand and use essential tools

A user wants to find every line containing the word error in notes.txt, regardless of whether the letters are upper or lower case. Which command does this?

  1. grep -c error notes.txt
  2. grep -i error notes.txt Correct answer.
  3. grep -v error notes.txt
  4. grep -n error notes.txt

Explanation

The -i option makes grep match case-insensitively, so Error, ERROR and error all qualify. The other options change which lines are selected or how the output is annotated.

Question 3Understand and use essential tools

In vim normal mode, which keystroke sequence removes the entire line the cursor is on?

  1. dd Correct answer.
  2. x
  3. yy
  4. cc

Explanation

The dd command deletes the current line and stores it in a register, leaving the cursor on the line below. The other keys either copy text, replace text, or remove a single character.

Question 4Understand and use essential tools

Which vim command saves the current buffer to disk and then exits the editor?

  1. :wq Correct answer.
  2. :e!
  3. :q!
  4. :w

Explanation

The :wq command performs a write followed by a quit, so changes are persisted before vim closes. The other commands either quit without saving, save without quitting, or discard changes by reloading the file.

Question 5Understand and use essential tools

In bash, which pattern expands to every filename in the current directory that ends with the extension .conf?

  1. ?.conf
  2. *.conf Correct answer.
  3. [.]conf
  4. .conf*

Explanation

The asterisk matches any string of characters, including an empty one, so *.conf matches any name ending in .conf. The question mark matches exactly one character, and the bracket expression matches a single character from a set.

Question 6Understand and use essential tools

Which command creates a symbolic link named latest that points to /var/log/messages?

  1. ln -d /var/log/messages latest
  2. ln -s /var/log/messages latest Correct answer.
  3. ln -f /var/log/messages latest
  4. ln /var/log/messages latest

Explanation

Without an option, ln creates a hard link; the -s option makes the new name a symbolic link that stores the target path. The -f option only controls whether an existing destination file is overwritten.

Question 7Understand and use essential tools

Which command sends only the error messages produced by command into errors.txt while normal output still appears on the terminal?

  1. command > errors.txt
  2. command < errors.txt
  3. command &> errors.txt
  4. command 2> errors.txt Correct answer.

Explanation

File descriptor 2 carries standard error, so 2> redirects only error output to the file while file descriptor 1 remains attached to the terminal. The other operators redirect standard output, both streams, or standard input.

Question 8Understand and use essential tools

Which grep option causes only the lines that do not contain the given pattern to be printed?

  1. -l
  2. -c
  3. -v Correct answer.
  4. -n

Explanation

The -v option inverts the sense of the match, so lines failing to match the pattern are selected. The remaining options affect counting, line numbering, and filename-only output.

Question 9Understand and use essential tools

Which command searches for the string timeout in every file below the /etc directory, including all subdirectories?

  1. grep -r timeout /etc Correct answer.
  2. grep -x timeout /etc
  3. grep -E timeout /etc
  4. grep timeout /etc

Explanation

The -r option makes grep descend recursively into directories, which is required to reach files in subdirectories. Without it grep acts only on the paths named on the command line.

Question 10Understand and use essential tools

Which command creates a gzip-compressed archive named backup.tar.gz from the directory /home/user?

  1. tar -xzvf backup.tar.gz /home/user
  2. tar -cjf backup.tar.gz /home/user
  3. tar -czf backup.tar.gz /home/user Correct answer.
  4. tar -tzf backup.tar.gz /home/user

Explanation

Creating an archive uses -c, gzip compression is selected with -z, and -f names the archive file, giving -czf. The compression option must match the .tar.gz name produced.

Question 11Understand and use essential tools

Which command extracts the bzip2-compressed archive archive.tar.bz2 into the current directory?

  1. tar -cjf archive.tar.bz2
  2. tar -tjf archive.tar.bz2
  3. tar -xzf archive.tar.bz2
  4. tar -xjf archive.tar.bz2 Correct answer.

Explanation

Extraction requires -x, bzip2 decompression is selected by -j, and -f names the archive to read. Using the wrong compression letter causes tar to fail on the actual file format.

Question 12Understand and use essential tools

In vim normal mode, which key sequence starts a search forward through the buffer for the text ServerName?

  1. :ServerName
  2. /ServerName Correct answer.
  3. *ServerName
  4. ?ServerName

Explanation

A forward slash opens a search prompt at the bottom of the screen and searches from the cursor position toward the end of the file. The question mark searches backward instead.

Question 13Understand and use essential tools

Which command locates every file named core.txt anywhere beneath the /var directory tree?

  1. ls -R /var core.txt
  2. grep -r core.txt /var
  3. locate /var -name core.txt
  4. find /var -name core.txt Correct answer.

Explanation

find takes a starting path and evaluates tests such as -name against each entry it walks recursively. locate does not walk the filesystem or accept a search root in this form.

Question 14Understand and use essential tools

Which command rebuilds the index that the locate utility reads so that newly created files appear in its results?

  1. makewhatis
  2. ldconfig
  3. updatedb Correct answer.
  4. mandb

Explanation

locate answers queries from a database file, and updatedb is the program that regenerates that database, normally through a scheduled job. Until the database is refreshed, recent files are invisible to locate.

Question 15Understand and use essential tools

Which command searches the short descriptions of installed manual pages for a keyword and lists the pages that mention it?

  1. man -k keyword Correct answer.
  2. man -f keyword
  3. man keyword
  4. info keyword

Explanation

The -k option turns man into a keyword search over the whatis database, returning page names with one-line summaries. Passing a bare name instead displays that single page.

Question 16Understand and use essential tools

In bash pathname expansion, which pattern matches filenames that consist of exactly one character followed by .log?

  1. ??.log
  2. *.log
  3. [a-z]*.log
  4. ?.log Correct answer.

Explanation

The question mark stands for exactly one arbitrary character, so ?.log matches a.log and 7.log but not ab.log. The asterisk stands for any number of characters, including zero.

Question 17Understand and use essential tools

Which command displays the final 20 lines of the file /var/log/secure?

  1. head -20 /var/log/secure
  2. tail -c 20 /var/log/secure
  3. tail -20 /var/log/secure Correct answer.
  4. head -n 20 /var/log/secure

Explanation

tail prints the end of a file, and a numeric argument given with -n, or as -20, sets how many lines are shown. head performs the same job but starts at the beginning of the file.

Question 18Understand and use essential tools

Which command creates a new SSH public and private key pair for the user running it?

  1. ssh-copy-id
  2. ssh-agent
  3. ssh-add
  4. ssh-keygen Correct answer.

Explanation

ssh-keygen generates the key pair and stores the private key with restrictive permissions alongside the matching .pub file. The other tools manage existing keys or the agent process.

Question 19Understand and use essential tools

Given the command line `command > out.txt 2>&1`, what is the result?

  1. It appends standard output and standard error to the end of out.txt.
  2. It saves both standard output and standard error in out.txt. Correct answer.
  3. It saves only standard error in out.txt and discards standard output.
  4. It saves standard output in out.txt and leaves errors on the screen.

Explanation

Redirections are processed left to right: > opens out.txt on file descriptor 1, then 2>&1 makes descriptor 2 point to the same place, so both streams land in the file. Because the operator used was >, any previous contents of the file are discarded.

Question 20Understand and use essential tools

Which command finds regular files under /data whose contents were last modified more than seven days ago?

  1. find /data -type f -mtime -7
  2. find /data -type f -mtime +7 Correct answer.
  3. find /data -type f -mtime 7
  4. find /data -type d -mtime +7

Explanation

The -mtime test counts 24-hour periods since the last modification, and a leading plus sign selects values greater than the given number. -type f restricts the result to regular files.

Question 21Understand and use essential tools

A file contains lines of colon-separated fields. Which command prints only the first field of every line in users.txt?

  1. cut -d: -f1 users.txt Correct answer.
  2. sed -n '1p' users.txt
  3. cut -f1 users.txt
  4. cut -c1 users.txt

Explanation

cut selects fields only when a delimiter is supplied, so -d: sets the colon as separator and -f1 chooses the first field. Options that select characters or omit the delimiter operate on different units.

Question 22Understand and use essential tools

Which pipeline reports how many times each distinct line occurs in list.txt?

  1. uniq -c list.txt | sort
  2. sort -c list.txt | uniq
  3. sort list.txt | uniq -c Correct answer.
  4. wc -l list.txt | uniq -c

Explanation

uniq collapses only adjacent duplicate lines, so the input must be sorted first to bring identical lines together. The -c option then prefixes each remaining line with its repeat count.

Question 23Understand and use essential tools

Which statement correctly describes a hard link to an existing file?

  1. It can point to a file that lives on a different filesystem.
  2. It shares the same inode number as the original file. Correct answer.
  3. It may be created for a directory with the ln command.
  4. It is removed automatically when the original path is deleted.

Explanation

A hard link is simply another directory entry pointing at the same inode, so both names report identical inode and link counts. The data survives until the last link to the inode is removed.

Question 24Understand and use essential tools

Which command reports what kind of data a file such as report.txt holds, printing a description like "ASCII text" or "gzip compressed data"?

  1. ls -l report.txt
  2. stat report.txt
  3. file report.txt Correct answer.
  4. type report.txt

Explanation

The file utility reads the first bytes of a file and compares them against known magic patterns, so its output describes the actual content type rather than the name or metadata. It is the standard way to distinguish text from binaries, archives, or images when an extension is missing or misleading.

Question 25Manage software

Which command lists every file that the installed package httpd placed on the system?

  1. rpm -qi httpd
  2. rpm -qd httpd
  3. rpm -ql httpd Correct answer.
  4. rpm -qc httpd

Explanation

The -q query selector combined with -l lists all files owned by an installed package. The other file-selection switches restrict output to configuration files (-c) or documentation files (-d), and -i prints descriptive metadata rather than file paths.

Question 26Manage software

Which command installs the vim-enhanced package and its dependencies from the configured repositories?

  1. dnf update vim-enhanced
  2. dnf install vim-enhanced Correct answer.
  3. dnf provides vim-enhanced
  4. dnf search vim-enhanced

Explanation

dnf install resolves dependencies and downloads the requested package plus anything it requires from enabled repositories. The update subcommand only moves already-installed packages to newer versions, while search queries names and summaries and provides maps a file or capability to a package.

Question 27Manage software

On RHEL 9, in which directory are repository definition files with a .repo extension normally stored?

  1. /etc/yum.repos.d Correct answer.
  2. /etc/dnf/repos.d
  3. /var/lib/dnf/repositories
  4. /etc/yum.conf.d

Explanation

DNF reads repository definitions from files ending in .repo inside /etc/yum.repos.d; the directory name is kept for historical compatibility. /var/lib/dnf holds runtime state such as cached metadata, not administrator-managed repo files.

Question 28Manage software

Which command removes the installed httpd package along with packages that depend on it?

  1. dnf uninstall --keepdeps httpd
  2. dnf remove httpd Correct answer.
  3. dnf clean httpd
  4. dnf group remove httpd

Explanation

dnf remove erases the named package and also removes packages that would be left with unmet dependencies as a result. dnf clean works on cached data only, and it does not take a package name as a removal target.

Question 29Manage software

Which command identifies the package that provides the file /usr/bin/htpasswd on a RHEL system?

  1. dnf provides /usr/bin/htpasswd Correct answer.
  2. dnf search /usr/bin/htpasswd
  3. dnf list /usr/bin/htpasswd
  4. dnf info /usr/bin/htpasswd

Explanation

dnf provides searches the file and capability lists of available packages, so an absolute path is accepted as the query. search matches only names and summaries, and list and info expect package names or globs rather than file paths.

Question 30Manage software

A repository stanza in /etc/yum.repos.d contains the line gpgcheck=0. What effect does that setting have?

  1. dnf imports the repository signing key automatically the first time the repository is used
  2. dnf keeps the repository disabled until a signing key is imported
  3. dnf accepts only packages signed with the Red Hat release key from that repository
  4. dnf installs packages from that repository without verifying their GPG signatures Correct answer.

Explanation

gpgcheck controls whether the signature of each downloaded package is verified against imported keys. Setting it to 0 disables that verification for the repository, so unsigned or untrusted packages are accepted. Key import is a separate step performed with rpm --import.

Question 31Manage software

Which command removes packages that were installed as dependencies and are no longer required by anything on the system?

  1. dnf group remove
  2. dnf autoremove Correct answer.
  3. dnf remove --orphans
  4. dnf clean all

Explanation

dnf autoremove removes leaf packages that were pulled in as dependencies and are not required by any user-installed package. It is the counterpart to a plain remove, which leaves such unused dependencies in place.

Question 32Manage software

What does the command rpm -V httpd report?

  1. It compares on-disk file attributes with package metadata Correct answer.
  2. It restores permissions on installed files from the package metadata
  3. It downloads fresh copies of any file whose checksum has changed
  4. It verifies the GPG signature of every file that is in the package

Explanation

The -V verify mode re-reads the recorded size, mode, checksum, and ownership of each packaged file and flags differences with a code such as S, M, or 5. It reports mismatches only; it never repairs, restores, or re-downloads anything.

Question 33Manage software

An administrator placed several RPM files in /srv/repo and wants to serve that directory as a local repository. Which command generates the metadata the repository needs?

  1. dnf config-manager --add-repo /srv/repo
  2. dnf makecache /srv/repo
  3. createrepo_c /srv/repo Correct answer.
  4. rpm --rebuilddb /srv/repo

Explanation

createrepo_c scans the directory of RPM files and writes the repodata directory containing primary, filelist, and other metadata that dnf requires. makecache only reads existing metadata, and config-manager --add-repo writes a .repo file but generates no metadata.

Question 34Manage software

Which command adds the Red Hat release key so that RPM can verify packages signed with it?

  1. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release Correct answer.
  2. gpg --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
  3. dnf config-manager --import-key /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
  4. rpm --add-key /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Explanation

rpm --import loads a public key into the RPM database, which is where signature verification looks for trusted keys. Importing into a user's GnuPG keyring with the gpg command does not make the key available to RPM.

Question 35Manage software

Which command enables the postgresql:13 module stream on the system without installing any of the module's packages?

  1. dnf module reset postgresql
  2. dnf module install postgresql:13/client
  3. dnf module enable postgresql:13 Correct answer.
  4. dnf module list postgresql:13

Explanation

dnf module enable records the requested stream as the enabled one for that module, so later installs draw from the right stream, and it installs nothing by itself. install would additionally install a profile's packages, and reset returns the module to its default stream.

Question 36Manage software

Which command installs all packages that belong to the group named RPM Development Tools?

  1. dnf group info "RPM Development Tools"
  2. dnf group remove "RPM Development Tools"
  3. dnf group install "RPM Development Tools" Correct answer.
  4. dnf group list "RPM Development Tools"

Explanation

dnf group install resolves the group name to its member packages, including mandatory and default packages, and installs them. The list and info verbs only display group contents.

Question 37Manage software

An administrator runs rpm -Uvh --nodeps on a package and the transaction succeeds. What is the most likely result?

  1. The transaction is queued and completed the next time dnf performs dependency solving
  2. RPM refuses the transaction because signatures cannot be verified without resolving dependencies
  3. RPM reinstalls the package over the existing version and skips its %pre scriptlets
  4. The package is installed even though its dependencies were never checked Correct answer.

Explanation

--nodeps suppresses dependency checking only, so the package is written to disk regardless of whether required libraries or capabilities are present. Scriptlets and signature verification still run, and the result is not queued for later completion.

Question 38Manage software

Which directive in the [main] section of /etc/dnf/dnf.conf prevents all kernel packages from ever being installed or updated by dnf?

  1. skip_if_unavailable=1
  2. best=False
  3. exclude=kernel* Correct answer.
  4. installonly_limit=3

Explanation

exclude accepts space-separated package name globs that dnf must ignore for all transactions, and it can also be set per repository. It filters packages out of install and update operations entirely rather than merely tolerating failures.

Question 39Manage software

Which command deletes cached repository metadata and downloaded packages so dnf must fetch fresh data on its next run?

  1. dnf makecache
  2. dnf check-update
  3. dnf clean all Correct answer.
  4. dnf repolist --refresh

Explanation

dnf clean all removes both cached metadata and cached package files from /var/cache/dnf. makecache and repolist --refresh download metadata but leave previously cached files in place.

Question 40Manage software

Which command reports which installed package owns the file /etc/httpd/conf/httpd.conf?

  1. rpm -ql /etc/httpd/conf/httpd.conf
  2. rpm -qf /etc/httpd/conf/httpd.conf Correct answer.
  3. rpm -qc /etc/httpd/conf/httpd.conf
  4. rpm -qi /etc/httpd/conf/httpd.conf

Explanation

-f asks RPM which package a given file path belongs to. The -l, -c, and -i switches take a package name and print file lists or information instead of resolving file ownership.

Question 41Manage software

Which command applies all available package updates from the enabled repositories?

  1. dnf update Correct answer.
  2. dnf check-update
  3. dnf repolist
  4. dnf makecache

Explanation

dnf update (upgrade is a synonym) computes a transaction that moves installed packages to the newest versions available in enabled repositories. check-update only reports what could be updated without changing the system.

Question 42Manage software

A downloaded file named httpd-2.4.rpm is in the current directory. Which command installs it and resolves its dependencies from the configured repositories?

  1. dnf install ./httpd-2.4.rpm Correct answer.
  2. dnf provides httpd-2.4.rpm
  3. rpm -Uvh httpd-2.4.rpm
  4. rpm -i --test --force httpd-2.4.rpm

Explanation

Passing dnf an argument that ends in .rpm and contains a path separator makes dnf treat it as a local package file and pull any missing dependencies from enabled repositories. rpm alone performs no dependency resolution, and --test only simulates the transaction.

Question 43Manage software

After an unclean shutdown, rpm queries fail with a database error. Which command rebuilds the RPM database from the installed package headers?

  1. rpm --rebuilddb Correct answer.
  2. rpm --initdb
  3. dnf makecache --refresh
  4. rpm -Va

Explanation

rpm --rebuilddb reconstructs the database indexes from the headers of installed packages, which repairs corruption from an interrupted transaction. --initdb creates a new empty database and would discard knowledge of installed packages.

Question 44Manage software

On a registered RHEL 9 system, which command enables the repository whose ID is rhel-9-for-x86_64-appstream-rpms?

  1. subscription-manager attach --enable rhel-9-for-x86_64-appstream-rpms
  2. dnf repos --enable rhel-9-for-x86_64-appstream-rpms
  3. subscription-manager repos --list rhel-9-for-x86_64-appstream-rpms
  4. subscription-manager repos --enable rhel-9-for-x86_64-appstream-rpms Correct answer.

Explanation

Red Hat entitlement repositories are enabled with subscription-manager repos --enable=<repo-id>, which regenerates the matching repository definition from the subscription. Merely listing repositories or running dnf without a valid repos subcommand does not enable them.

Question 45Manage software

Which command creates a new repository definition from a URL using the dnf-plugins-core utilities?

  1. dnf repo create http://repo.example.com/AppStream
  2. dnf config-manager --add-repo http://repo.example.com/AppStream Correct answer.
  3. dnf config-manager --save http://repo.example.com/AppStream
  4. dnf config-manager --set-enabled http://repo.example.com/AppStream

Explanation

config-manager --add-repo writes a new .repo file into /etc/yum.repos.d that points at the supplied URL. --set-enabled only toggles the enabled flag on a repository that already exists.

Question 46Manage software

Transaction 5 in dnf history records a known-good state, and several later transactions have been applied. Which command returns the installed package set to exactly that state?

  1. dnf history redo 5
  2. dnf history undo 5
  3. dnf history rollback 5 Correct answer.
  4. dnf history info 5

Explanation

history rollback takes an earlier transaction ID and performs all the inverse operations needed to return the system to the state recorded at that point, effectively undoing every later transaction. history undo only reverses the single transaction given as its argument.

Question 47Create simple shell scripts

Which first line in a script causes the kernel to run the file with the Bash interpreter?

  1. #!/bin/bash Correct answer.
  2. #/bin/bash
  3. #!/usr/bin/env
  4. !#/bin/bash

Explanation

A shebang line starts with the two characters #! followed by the absolute path of an interpreter. When the script is executed directly, the kernel reads that line and launches the named program with the script as its argument.

Question 48Create simple shell scripts

Immediately after a command finishes, which special variable holds its exit status?

  1. $$
  2. $?
  3. $! Correct answer.
  4. $#

Explanation

The shell stores the exit status of the most recently completed foreground command in $?, where 0 means success and non-zero means failure. Scripts read this variable to decide whether to continue or abort.

Question 49Create simple shell scripts

A script is invoked as ./report.sh alpha beta. Which expansion yields the value alpha inside the script?

  1. $@
  2. $#
  3. $0
  4. $1 Correct answer.

Explanation

Positional parameters are numbered from 1 after the script name, so $1 is the first argument. $0 always refers to the script itself.

Question 50Create simple shell scripts

Inside a script invoked with three arguments, what does $# expand to?

  1. 0
  2. 3 Correct answer.
  3. 2
  4. The script file name

Explanation

$# is the number of positional parameters supplied to the script. The script name itself is $0 and is not counted, so three arguments give 3.