LPIC-1 · domain
Shells, Scripting and Data Management
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.
Focused practice
Practice Shells, Scripting and Data Management questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Shells, Scripting and Data Management
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.
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
Watch out for
Common Shells, Scripting and Data Management exam traps
- ▸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.
Question index
All Shells, Scripting and Data Management questions (44)
Click any question to see the full explanation, or start a practice session above.
A 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?
Medium2A 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?
Medium3Refer to the exhibit. A user gets this error when running a script. What is the most likely cause?
Medium4A 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?
Hard5A script reads a CSV file where fields may contain commas within quoted strings. Which approach correctly parses such fields?
Hard6A script starts multiple background processes. An administrator wants to wait for all background jobs to complete before proceeding. Which command should be used?
Hard7A 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?
Medium8Refer to the exhibit. An administrator wants to unset the BASH_ALIASES associative array. Which command will correctly remove it?
Easy9A system administrator wants to display all lines in /var/log/syslog that do NOT contain the string 'error'. Which command accomplishes this?
Easy10A shell script contains the following line: `find /data -type f -name '*.tmp' -exec rm {} \;`. What is the effect of this command?
Hard11A 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?
Medium12Match each package manager to its associated distribution family.
Medium13A 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?
Medium14A 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?
Hard15Which sed command will replace the first occurrence of 'foo' with 'bar' on each line of a file?
Easy16An administrator wants to list all lines in a log file that do NOT contain the word 'ERROR'. Which command should be used?
Easy17A 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?
Hard18A 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?
Hard19A 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?
Hard20A script needs to read a file line by line, preserving leading and trailing whitespace and backslashes. Which loop construct should be used?
Medium21Which TWO of the following are true about the 'source' command in bash?
Medium22A script uses the command substitution: files=$(ls). Which statement about the resulting value of files is true?
Medium23Which TWO of the following are valid ways to capture the output of a command into a variable in Bash?
Easy24A 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?
Easy25Given 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?
Medium26A 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?
Medium27A 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?
Hard28A 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?
Medium29A 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?
Medium30Which THREE statements are true about the sed command?
Hard31Refer 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?
Easy32A 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.)
Medium33Refer 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?
Hard34A user wants to view the first 10 lines of a log file named /var/log/syslog. Which command should they use?
Easy35In a bash script, a variable 'file' is set to '/var/log/syslog'. Which expansion will yield the string '/var/log'?
Medium36A 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?
Medium37A 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?
Easy38A 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?
Easy39An 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?
Hard40An administrator needs to replace all occurrences of 'old_host' with 'new_host' in the file /etc/hosts. Which sed command should be used?
Easy41A 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?
Easy42Which TWO of the following commands can be used to replace text patterns in a file and output the result?
Medium43Which THREE of the following are types of expansion performed by the bash shell during command parsing?
Medium44Refer to the exhibit. When will the cron job execute?
EasyOther domains
All LPIC-1 exam domains
Frequently asked questions
- What does the Shells, Scripting and Data Management domain cover on the LPIC-1 exam?
- 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.
- How many questions are in this domain?
- This page lists all 44 Shells, Scripting and Data Management questions in the LPIC-1 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Shells, Scripting and Data Management questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.