Courseiva

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.

44 questions13 easy19 medium12 hard

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.

1

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?

Medium
2

A 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?

Medium
3

Refer to the exhibit. A user gets this error when running a script. What is the most likely cause?

Medium
4

A 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?

Hard
5

A script reads a CSV file where fields may contain commas within quoted strings. Which approach correctly parses such fields?

Hard
6

A script starts multiple background processes. An administrator wants to wait for all background jobs to complete before proceeding. Which command should be used?

Hard
7

A 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?

Medium
8

Refer to the exhibit. An administrator wants to unset the BASH_ALIASES associative array. Which command will correctly remove it?

Easy
9

A system administrator wants to display all lines in /var/log/syslog that do NOT contain the string 'error'. Which command accomplishes this?

Easy
10

A shell script contains the following line: `find /data -type f -name '*.tmp' -exec rm {} \;`. What is the effect of this command?

Hard
11

A 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?

Medium
12

Match each package manager to its associated distribution family.

Medium
13

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?

Medium
14

A 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?

Hard
15

Which sed command will replace the first occurrence of 'foo' with 'bar' on each line of a file?

Easy
16

An administrator wants to list all lines in a log file that do NOT contain the word 'ERROR'. Which command should be used?

Easy
17

A 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?

Hard
18

A 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?

Hard
19

A 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?

Hard
20

A script needs to read a file line by line, preserving leading and trailing whitespace and backslashes. Which loop construct should be used?

Medium
21

Which TWO of the following are true about the 'source' command in bash?

Medium
22

A script uses the command substitution: files=$(ls). Which statement about the resulting value of files is true?

Medium
23

Which TWO of the following are valid ways to capture the output of a command into a variable in Bash?

Easy
24

A 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?

Easy
25

Given 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?

Medium
26

A 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?

Medium
27

A 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?

Hard
28

A 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?

Medium
29

A 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?

Medium
30

Which THREE statements are true about the sed command?

Hard
31

Refer 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?

Easy
32

A 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.)

Medium
33

Refer 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?

Hard
34

A user wants to view the first 10 lines of a log file named /var/log/syslog. Which command should they use?

Easy
35

In a bash script, a variable 'file' is set to '/var/log/syslog'. Which expansion will yield the string '/var/log'?

Medium
36

A 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?

Medium
37

A 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?

Easy
38

A 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?

Easy
39

An 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?

Hard
40

An administrator needs to replace all occurrences of 'old_host' with 'new_host' in the file /etc/hosts. Which sed command should be used?

Easy
41

A 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?

Easy
42

Which TWO of the following commands can be used to replace text patterns in a file and output the result?

Medium
43

Which THREE of the following are types of expansion performed by the bash shell during command parsing?

Medium
44

Refer to the exhibit. When will the cron job execute?

Easy

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.
lpi-lpic1 LPI-LPIC1 shells scripting Practice Questions