Skip to content
TryHired.
Interview prep · Technical · GNU bash 5.3.9

Linux interview questions: commands with real output

The command-line questions system administrators, DevOps engineers and developers get, each answered in plain words and run on sample files.

Updated Nov 15, 2026 · Every example run on GNU bash 5.3.9 · questions: TryHired
Quick answer

Linux interviews test whether you can work on the command line: searching files with grep and find, slicing text with cut, awk and sed, combining tools with pipes and redirection, reading exit codes, quoting correctly, and writing safe scripts with set -euo pipefail and trap. Below are 17 questions from basic to advanced; the commands run on small sample files and the output shown is real.

Sample files

The files every command runs on

Advice

Each example starts in a fresh, empty directory that this script fills with a short application log and a small CSV of fictional staff, so examples do not affect each other.

mkdir -p logs data
printf '%s\n' '2026-11-02 09:14:01 INFO  api   started on port 8080' '2026-11-02 09:15:22 WARN  api   slow response 1840ms /search' '2026-11-02 09:16:05 ERROR db    connection refused host=db1' '2026-11-02 09:16:07 INFO  api   retry scheduled' '2026-11-02 09:17:44 ERROR api   timeout /checkout' '2026-11-02 09:18:10 INFO  worker job 42 done' '2026-11-02 09:19:31 ERROR db    connection refused host=db2' > logs/app.log
printf '%s\n' 'name,dept,salary' 'Ava,Engineering,98000' 'Ben,Sales,61000' 'Cara,Engineering,112000' 'Dev,Support,52000' 'Eli,Sales,67000' > data/staff.csv
printf 'alpha\nbeta\n' > notes.txt
Basic

Basic linux interview questions

Advice

Basic1. How do you search for text inside a file?

grep prints the lines that match a pattern. -n adds line numbers, -i ignores case, -c counts matching lines instead of printing them, and -v inverts the match.

Bash
grep -n ERROR logs/app.log
echo '---'
grep -c ERROR logs/app.log
echo '---'
grep -ic 'info' logs/app.log
Output (GNU bash 5.3.9)
3:2026-11-02 09:16:05 ERROR db    connection refused host=db1
5:2026-11-02 09:17:44 ERROR api   timeout /checkout
7:2026-11-02 09:19:31 ERROR db    connection refused host=db2
---
3
---
3

Checked against: GNU grep manual

Basic2. How do you show the first or last lines of a file?

head prints the start of a file and tail the end; -n sets how many lines. tail -f keeps the file open and prints new lines as they arrive, which is how people watch a live log.

Bash
head -n 2 logs/app.log
echo '---'
tail -n 2 logs/app.log
Output (GNU bash 5.3.9)
2026-11-02 09:14:01 INFO  api   started on port 8080
2026-11-02 09:15:22 WARN  api   slow response 1840ms /search
---
2026-11-02 09:18:10 INFO  worker job 42 done
2026-11-02 09:19:31 ERROR db    connection refused host=db2

Basic3. How do you count lines, words and characters?

wc counts them: -l lines, -w words, -c bytes. Piping into wc -l is the usual way to count results from another command.

Bash
wc -l logs/app.log data/staff.csv
echo '---'
grep ERROR logs/app.log | wc -l
Output (GNU bash 5.3.9)
  7 logs/app.log
  6 data/staff.csv
 13 total
---
3

Basic4. What is the difference between >, >> and 2>?

> sends standard output to a file and replaces its contents, >> appends, and 2> redirects standard error (file descriptor 2). 2>&1 sends errors to wherever standard output is going.

Bash
echo first > out.txt
echo second >> out.txt
cat out.txt
echo '---'
ls missing-file 2> err.txt
echo "exit code: $?"
wc -l < err.txt
Output (GNU bash 5.3.9)
first
second
---
exit code: 2
1

Checked against: GNU Bash Reference Manual

Basic5. How do you find files by name or type?

find walks a directory tree and filters by tests such as -name, -type f (regular file) or -type d (directory). Its output order is not sorted, so pipe it to sort when the order matters.

Bash
find . -type f -name '*.csv' | sort
echo '---'
find . -type d | sort
Output (GNU bash 5.3.9)
./data/staff.csv
---
.
./data
./logs

Basic6. How do you pick out a column from a CSV or log line?

cut splits on a single delimiter (-d) and keeps fields (-f). awk splits on whitespace by default, or on -F, and lets you print, compute and filter per field.

Bash
cut -d, -f1,3 data/staff.csv
echo '---'
awk '{print $3, $4}' logs/app.log | head -n 3
Output (GNU bash 5.3.9)
name,salary
Ava,98000
Ben,61000
Cara,112000
Dev,52000
Eli,67000
---
INFO api
WARN api
ERROR db
Intermediate

Intermediate linux interview questions

Advice

Intermediate7. How do you count the most frequent values?

Extract the field, sort it so equal values sit together, count runs with uniq -c, then sort numerically in reverse. This sort | uniq -c | sort -rn pattern appears in a lot of log questions.

Bash
awk '{print $3}' logs/app.log | sort | uniq -c | sort -rn
Output (GNU bash 5.3.9)
      3 INFO
      3 ERROR
      1 WARN

Intermediate8. How do you sum or average a column with awk?

awk keeps variables between lines. NR is the line number, so NR>1 skips the header; the END block runs once after the last line.

Bash
awk -F, 'NR>1 {sum += $3; n++} END {print "total", sum; print "average", sum/n}' data/staff.csv
Output (GNU bash 5.3.9)
total 390000
average 78000

Intermediate9. How do you group and total values per key?

Use an awk associative array keyed by the group, then print it in the END block. awk does not promise any order for a for-in loop, so sort the result.

Bash
awk -F, 'NR>1 {s[$2] += $3} END {for (d in s) print d, s[d]}' data/staff.csv | sort
Output (GNU bash 5.3.9)
Engineering 210000
Sales 128000
Support 52000

Intermediate10. How do you replace text with sed?

sed 's/old/new/' replaces the first match on each line and s/old/new/g replaces every match. -i edits the file in place, so try the command without -i first.

Bash
sed 's/ERROR/E/' logs/app.log | grep '^2026' | head -n 3
echo '---'
sed -n '3,4p' logs/app.log
Output (GNU bash 5.3.9)
2026-11-02 09:14:01 INFO  api   started on port 8080
2026-11-02 09:15:22 WARN  api   slow response 1840ms /search
2026-11-02 09:16:05 E db    connection refused host=db1
---
2026-11-02 09:16:05 ERROR db    connection refused host=db1
2026-11-02 09:16:07 INFO  api   retry scheduled

Intermediate11. What do $?, && and || do?

$? holds the exit status of the last command: 0 means success, anything else is failure. a && b runs b only if a succeeded; a || b runs b only if a failed.

Bash
grep -q timeout logs/app.log && echo 'found timeout'
grep -q panic logs/app.log || echo 'no panic lines'
grep -q panic logs/app.log
echo "status: $?"
Output (GNU bash 5.3.9)
found timeout
no panic lines
status: 1

Checked against: GNU Bash Reference Manual

Intermediate12. What is the difference between single and double quotes in bash?

Single quotes keep every character literal, so $name stays as text. Double quotes still expand variables and command substitution, but stop the result from being split into separate words.

Bash
name='Ava Lee'
echo 'single: $name'
echo "double: $name"
set -- $name
echo "unquoted gives $# words"
set -- "$name"
echo "quoted gives $# word"
Output (GNU bash 5.3.9)
single: $name
double: Ava Lee
unquoted gives 2 words
quoted gives 1 word

Intermediate13. How do you loop over lines of a file?

Use while IFS= read -r line; do ...; done < file. -r keeps backslashes, IFS= keeps leading spaces, and redirecting into the loop avoids running it in a subshell.

Bash
count=0
while IFS=, read -r name dept salary; do
  [ "$dept" = Sales ] && count=$((count + 1))
done < data/staff.csv
echo "sales staff: $count"
Output (GNU bash 5.3.9)
sales staff: 2
Advanced

Advanced linux interview questions

Advice

Advanced14. How do you extract only the matching part of a line?

grep -o prints just the matched text, one match per line, and -E enables extended regular expressions. That turns a log into a list of values you can count.

Bash
grep -oE 'host=[a-z0-9]+' logs/app.log
echo '---'
grep -oE '[0-9]+ms' logs/app.log
Output (GNU bash 5.3.9)
host=db1
host=db2
---
1840ms

Checked against: GNU grep manual

Advanced15. What does set -euo pipefail do, and why do scripts use it?

-e stops the script when a command fails, -u treats unset variables as errors, and -o pipefail makes a pipeline fail if any command in it fails, not just the last one. Without pipefail, a failing grep in the middle of a pipeline is hidden.

Bash
false | true
echo "without pipefail: $?"
set -o pipefail
false | true
echo "with pipefail: $?"
Output (GNU bash 5.3.9)
without pipefail: 0
with pipefail: 1

Checked against: GNU Bash Reference Manual

Advanced16. How do you clean up temporary files even when a script fails?

trap registers a command to run when the shell exits or receives a signal. A trap on EXIT runs on success and on failure, so it is the standard place to delete temp files.

Bash
bash -c 'tmp=scratch.tmp; touch "$tmp"; trap "rm -f $tmp; echo cleaned up" EXIT; echo working; exit 3'
echo "script exit: $?"
ls scratch.tmp 2>/dev/null || echo 'temp file is gone'
Output (GNU bash 5.3.9)
working
cleaned up
script exit: 3
temp file is gone

Checked against: GNU Bash Reference Manual

Advanced17. What is /proc and what can you read from it?

/proc is a virtual file system the kernel generates on demand: it holds no files on disk. Each running process has a numbered directory, and files such as /proc/meminfo and /proc/cpuinfo report memory and CPU details. Tools like ps and free read from it. (No output is shown here because the build machine is not a Linux kernel.)

Checked against: Linux kernel documentation: the /proc filesystem

Practice

How to practice with this page

Advice
  • Read the question, write your own command, then compare with the example.
  • Explain each part of a pipeline out loud: interviewers want the reasoning.
  • Recreate the sample files with the script above and run the commands yourself.
  • Pair this page with networking and process basics if the role is in operations.
Next

Related interview prep and tools

Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.

FAQ

Questions people ask

Which Linux commands come up often in interviews?
Expect file navigation and permissions, grep, find, sort and uniq, awk and sed, pipes and redirection, exit codes, processes (ps, kill, top) and basic networking checks. Practice explaining what each part of a one-liner does.
Do I need to know shell scripting for a Linux interview?
For system administration, DevOps and SRE roles, usually yes: loops, conditionals, quoting, exit codes and safe script settings such as set -euo pipefail. Help desk roles focus more on commands than scripts.
Were these examples run on Linux?
They were run in GNU bash with the GNU coreutils, grep and awk tools on the build machine. These text-processing commands behave the same on Linux distributions; questions that depend on the Linux kernel are explained without output.
Method

How this page is built

TryHired wrote these questions and answers. Every code block on this page was executed with GNU bash 5.3.9 when the page was built (2026-11-15), and the output shown is the real output; the build stops if any example fails. The question list is general practice: it does not predict what a particular employer will ask.

What this page can't tell you
  • Interviewers ask different questions for different roles and levels.
  • Answers are short explanations, not complete references.
  • Examples ran in GNU bash with GNU coreutils, grep, sed and awk on the build machine; these text commands behave the same on Linux distributions, but kernel-level details (processes, /proc, permissions on special files) are explained without output.
Sources
  1. GNU Bash Reference Manual (read 2026-11-15)
  2. GNU grep manual (read 2026-11-15)
  3. Linux kernel documentation: the /proc filesystem (read 2026-11-15)