RHCSA RHCSA Essential Command-Line Tools 4 — Questions and Answers
Question 1: What does the redirection operator '>>' do?
- Appends stdout to a file without overwriting (Correct answer)
- Overwrites a file with stdout
- Redirects stderr to a file
- Creates a new file and writes stdout to it
Correct answer: Appends stdout to a file without overwriting
>> appends standard output to the end of a file, preserving existing content.
Question 2: Which command lists all environment variables currently set in the shell?
- env (Correct answer)
- set --env
- printenv --all
- export -l
Correct answer: env
env without arguments prints all environment variables and their values to stdout.
Question 3: When using 'find', what does '-mtime -2' mean?
- Files modified within the last 2 days (Correct answer)
- Files modified more than 2 days ago
- Files modified exactly 2 days ago
- Files with a modification timestamp of 2
Correct answer: Files modified within the last 2 days
In find, -mtime -2 selects files whose modification time is less than 2*24 hours ago (within the last 2 days).
Question 4: What does 'chmod 755 script.sh' set on the file?
- Owner: rwx, Group: r-x, Others: r-x (Correct answer)
- Owner: rwx, Group: rwx, Others: rwx
- Owner: r-x, Group: r-x, Others: r-x
- Owner: rwx, Group: r--, Others: r--
Correct answer: Owner: rwx, Group: r-x, Others: r-x
Octal 7=rwx, 5=r-x, so 755 gives the owner full permissions and group/others read+execute.
Question 5: Which command creates a hard link named 'link1' pointing to 'file1'?
- ln file1 link1 (Correct answer)
- ln -s file1 link1
- link file1 link1
- cp --link file1 link1
Correct answer: ln file1 link1
ln without -s creates a hard link; both names refer to the same inode on the same filesystem.
Question 6: What is the effect of 'echo $?' after a command returns successfully?
- Prints 0 (Correct answer)
- Prints 1
- Prints the PID of the last command
- Prints the command name
Correct answer: Prints 0
$? holds the exit status of the most recently executed command; 0 indicates success.
Question 7: Which command would archive and compress the directory '/data' into a gzip-compressed tarball named 'data.tar.gz'?
- tar -czf data.tar.gz /data (Correct answer)
- tar -cjf data.tar.gz /data
- gzip -r /data data.tar.gz
- tar -xzf data.tar.gz /data
Correct answer: tar -czf data.tar.gz /data
tar -czf uses -c to create, -z for gzip compression, and -f to name the output file.
What does the redirection operator '>>' do?