You must be able to read and write Bash scripts that set shell options, expand variables safely, and transform text with sed and related filters. The single most important thing is predicting exact output: quote expansions, know which parameter expansion assigns versus substitutes, and use sed's g flag for global replacement.
Start practicing
Shells, Scripting and Data Management — choose a session length
Free · No account required
Domain overview
This LPIC-1 domain covers writing and reading Bash scripts, managing shell environment and variables, and processing text data with standard filters. Questions present short scripts or one-line commands and ask you to predict output, choose correct syntax, or select the right tool for a file-editing task.
Exam objectives
Using set -e and set -x to control script failure and tracing behavior
Understanding command substitution with $(...) and backticks, including word splitting
Applying parameter expansion forms such as ${var:-default}, ${var:=default}, and ${var:+alt}
Editing files in place with sed, including global substitution and address matching
Confusing ${var:-default} with ${var:=default}: the former only substitutes, the latter assigns the default back to the variable.
Forgetting that unquoted command substitution like files=$(ls) splits on whitespace and is subject to globbing.
Omitting the g flag in sed s/old/new/ so only the first match per line is replaced.
Click any question to see the full explanation and answer options, or start a focused practice session above.
A system administrator writes a script that extracts data from a CSV file and inserts it into a database. The script works correctly when run manually but fails when executed by cron. Which environment variable is most likely causing the issue?
2A developer needs to ensure a bash script exits immediately if any command fails, and also prints each command before executing it. Which set of shell options should be used at the beginning of the script?
3A script contains the following line: for i in $(cat file.txt); do echo $i; done. The file file.txt contains a single line with multiple words. How many times will the loop execute?
4Which THREE statements are true about the sed command?
5A system administrator needs to ensure that a bash script continues executing even if any command in the script fails. Which of the following should be used at the beginning of the script?
6Match each package manager to its associated distribution family.
7An administrator wants to list all lines in a log file that do NOT contain the word 'ERROR'. Which command should be used?
8In a bash script, a variable 'file' is set to '/var/log/syslog'. Which expansion will yield the string '/var/log'?
9Which sed command will replace the first occurrence of 'foo' with 'bar' on each line of a file?
10Given a file with lines like 'John:23:Engineer', which awk command prints only the name and department (first and third fields) separated by a space?
11A script reads a CSV file where fields may contain commas within quoted strings. Which approach correctly parses such fields?
12Which TWO of the following are true about the 'source' command in bash?
13Refer to the exhibit. An administrator installed a new command in /opt/bin/ but cannot run it without specifying the full path. What is the likely cause?
14Refer to the exhibit. When will the cron job execute?
15A system administrator wants to display all lines in /var/log/syslog that do NOT contain the string 'error'. Which command accomplishes this?
16A script produces both standard output and error messages. An administrator wants to save the output to 'out.log' and the error messages to 'err.log', but also wants to see both on the terminal. Which command achieves this?
17An administrator needs to replace all occurrences of 'old_host' with 'new_host' in the file /etc/hosts. Which sed command should be used?
18A directory contains files with spaces and special characters in their names. An administrator wants to delete all files older than 30 days using find and xargs. Which command is safe?
19A script starts multiple background processes. An administrator wants to wait for all background jobs to complete before proceeding. Which command should be used?
20Refer to the exhibit. An administrator runs this command expecting to capture both stdout and stderr into output.txt. However, the file contains only stdout. What is the error?
21Refer to the exhibit. An administrator wants to unset the BASH_ALIASES associative array. Which command will correctly remove it?
22A user needs to schedule a backup script to run every weekday at 2:00 AM. Which command should they use to set up this recurring job?
23A shell script uses the variable expansion ${var:-default} to set a default value for an environment variable. The script prints unexpected output when the variable is set to an empty string. Which expansion should be used to ensure the default is only used when the variable is unset, not when it is empty?
24A system administrator wants to monitor a log file in real-time for lines containing 'ERROR' and write them to a separate file. Which command combination is most appropriate?
25Which TWO of the following commands can be used to replace text patterns in a file and output the result?
26Which THREE of the following are types of expansion performed by the bash shell during command parsing?
27A senior administrator runs a script that processes a CSV file. The script contains the following snippet: 'for field in $(cat data.csv); do ...'. The data.csv file contains lines like: 'John Doe, 123 Main St, Springfield'. The script fails to process correctly, splitting fields incorrectly and causing errors. Which of the following is the most appropriate fix?
28Which TWO of the following are valid ways to capture the output of a command into a variable in Bash?
29Refer to the exhibit. A user gets this error when running a script. What is the most likely cause?
30A systems administrator maintains a Linux web server running Apache HTTP Server (version 2.4) with three virtual hosts. The server logs are stored in /var/log/httpd/ and are rotated using logrotate, which is configured with the default settings that came with the Apache package. The administrator has noticed that after the nightly log rotation, the main access log file (access_log) is empty, while the rotated log files (e.g., access_log.1, access_log.2) contain the previous day's data. Furthermore, new HTTP requests are being logged into the most recent rotated file (access_log.1) instead of the current access_log file. The administrator has verified that the logrotate cron job runs successfully, and that the log files are owned by the root user with read/write permissions for the root group. No errors appear in the system logs. The Apache service continues to run and serve web pages. Which of the following actions should the administrator take to ensure that Apache writes new log entries to the current access_log file after rotation?
31A user runs the command `echo $HOME` in a Bash shell and receives the output `/home/alice`. A colleague later runs the same command in a different shell and gets `/root`. Which type of shell variable is being displayed?
32A backup script stores its log file path in the variable LOGFILE and needs to append a timestamp line to that file. Which command correctly appends the output of the `date` command to the file named in the variable?
33A Linux administrator needs to extract all lines from `/var/log/syslog` that contain the word `error` (case-insensitive) and save them to `errors.txt`. Which command accomplishes this?
34A user wants to set a shell variable named DEPLOY_ENV to the value 'staging' in the current Bash session so that child processes can read it. Which command accomplishes this?
35A script needs to read a file line by line, preserving leading and trailing whitespace and backslashes. Which loop construct should be used?
36A system administrator runs a script that contains the line: trap 'echo "Cleaning up..."' EXIT. The script is executed and then receives SIGINT (Ctrl+C) before normal completion. What happens?
37A script uses the command substitution: files=$(ls). Which statement about the resulting value of files is true?
38An administrator needs to extract only the fifth field from a colon-delimited file, but some lines contain fewer than five fields and must be skipped rather than printed as empty. Which awk program accomplishes this?
39A shell script must exit immediately with a non-zero status if any command fails, and it must also treat an unset variable as an error. Which line should be placed at the top of the script?
40A user wants to view the first 10 lines of a log file named /var/log/syslog. Which command should they use?
41A junior administrator needs to extract only the lines containing the word 'ERROR' from /var/log/syslog, but the log may have inconsistent casing (e.g., 'ERROR', 'Error', 'error'). Which command will print all such lines while ignoring case?
42A shell script contains the following line: `find /data -type f -name '*.tmp' -exec rm {} \;`. What is the effect of this command?
43A shell script contains a function named `cleanup` that must run automatically when the script exits, whether it finishes normally or is terminated by a signal. Which construct should be used to register this function?
44A user needs to find all lines in a file that contain the word `error` while ignoring case, and also print the line number for each match. Which TWO `grep` invocations accomplish this? (Choose two.)
Deep-dive questions
The most-searched questions in this domain — detailed explanations, worked examples, full answer breakdowns.
You must be able to read and write Bash scripts that set shell options, expand variables safely, and transform text with sed and related filters. The single most important thing is predicting exact output: quote expansions, know which parameter expansion assigns versus substitutes, and use sed's g flag for global replacement.
The Courseiva LPIC-1 question bank contains 44 questions in the Shells, Scripting and Data Management domain, covering the 14% of the exam attributed to this domain in the official LPI blueprint. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Shells, Scripting and Data Management domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included