Linux command-line toolkit interview questions: pipes, grep, sed, awk, find
Reviewed by Mark Dickie · Last updated
7 questions on this page you can answer and see marked on the spot. Go to the first one
The Linux command-line toolkit is the set of shell utilities, such as grep and sed, that you use to search, edit, and manage files and processes from a terminal. Interviewers mostly test whether you can chain these tools with pipes and redirection to answer a question on a live machine, not whether you can recite their flags. Expect questions on text filtering, file search, permissions, process inspection, and exit status, since they come up in most ops and backend screens. For each tool, know what it reads from stdin, what it writes to stdout, and what it returns as an exit code.
Which command-line skills do interviewers test first?
| Area | Command or option to know | What the interviewer checks |
|---|---|---|
| Text filtering | grep -E, grep -rn, grep -v | Whether you pick extended regex on purpose and know what -v inverts |
| Stream editing | sed -i 's/old/new/g' file | Whether you know -i edits in place and keeps no backup unless you pass a suffix |
| Field extraction | awk -F: '{print $1}' /etc/passwd | Whether you split on a delimiter instead of counting columns by eye |
| File search | find . -name '*.log' -mtime +7 -exec rm {} + | Whether you know -exec ... + batches arguments and that -delete is a separate action |
| Safe piping | find . -print0 | xargs -0 wc -l | Whether you handle spaces and newlines in filenames |
| Redirection | cmd 2>&1 | tee out.log | Whether you know the order of 2>&1 changes where stderr goes |
| Permissions | chmod 640, umask, ls -l | Whether you read the mode bits and know what umask subtracts from the default |
| Processes | ps aux, kill -TERM, ss -tlnp | Whether you can find what holds a port and why kill -9 comes last |
| Exit status | $?, set -o pipefail | Whether you know a pipeline reports only its last command's status unless pipefail is set |
How should you practise the command line before an interview?
- Run
du -sh /var/* | sort -h | tail -5and explain what each stage passes to the next. - Write a
findcommand that lists files over 100 MB, then rerun it with-print0andxargs -0and say why the second version is safer. - Print lines 10 to 20 of a file with
sed -n '10,20p'and again withawk 'NR>=10 && NR<=20', and note that both read the file to its end. Then stop reading at line 20 withsed -n '10,20p;20q'orawk 'NR>20{exit} NR>=10', and explain why those exit early. - Start
sleep 300 &, find its PID withpgrep -a sleep, stop it withkill -TERM, and confirm it is gone withps -p PID. - As a non-root user, run
chmod 000on a scratch file, try to read it, then restore it and explain each octal digit.
Key facts
- Tarmac has 15 Linux interview questions on this topic, 10 of them on this page, at difficulty 1–4 of 5.
- Tarmac tracked 1,535 job postings asking for Linux in November 2026.
- Roles asking for Linux advertise a median base salary of £70,000, across 470 job postings as of November 2026.
- Tarmac last reviewed these Linux interview questions on 3 December 2026.
At a glance
| Questions | 10 shown · 15 in the bank |
|---|---|
| Difficulty | 1–4 of 5 |
| Formats | Multiple choice, Fill in the blank |
What you'll review
- networking commands
- file and process inspection
- text processing
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
Which Linux command sends ICMP Echo Request packets to a remote host to test network reachability and measure round-trip latency?#
Options
Show answer
ping is the Linux command that sends ICMP Echo Request packets to a remote host to test network reachability and measure round-trip latency. It reports whether each Echo Reply is received and the round-trip time for each, making it the standard tool for basic connectivity checks.
ping uses ICMP Echo Request/Echo Reply messages to verify that a host is reachable and reports round-trip times for each reply. hostname only displays or sets the system's name, netstat shows routing tables and socket statistics, and dig performs DNS lookups — none of which involve ICMP Echo Request packets.
The Linux command ls -l displays a long listing of files. In the permission string drwxr-xr-x, the very first character indicates the file _____. Common values include d for directory and - for a regular file.#
Show answer
The Linux command ls -l displays a long listing of files. In the permission string drwxr-xr-x, the very first character indicates the file type. Common values include d for directory and - for a regular file.
In the long-format output of ls -l, the first character of each permission string encodes the file type: d for directory, - for regular file, l for symbolic link, c for character device, b for block device, and so on. The remaining nine characters represent read/write/execute permissions for owner, group, and others.
In GNU grep, what does the -v flag do?#
Options
Show answer
In grep, the -v flag inverts the match so that lines NOT containing the pattern are printed. By default grep prints matching lines; -v flips that behavior. Other common flags include -i for case-insensitive matching, -c for a count, and -n to show line numbers.
The -v (or --invert-match) option inverts the sense of matching: grep prints every line that does NOT contain the pattern. -i is case-insensitive matching, -c prints a count of matching lines, and -n prefixes matching lines with line numbers.
You are debugging a process (PID 5170) that has an unexpectedly large number of open files. Which command lists every open file descriptor currently belonging to that process, including regular files, network sockets, and pipes?#
Options
Show answer
Use lsof -p <PID> to list every open file descriptor for a given process, including regular files, sockets, and pipes. The command reads kernel state via /proc and presents each entry with its FD, type, device, and node. Alternatives like ps, strace, or du do not report the current set of open descriptors.
lsof -p 5170 lists all files held open by the process with PID 5170, showing the file descriptor, type, device, and node for each entry. ps aux | grep 5170 only shows process metadata from the process table, not open files. strace -p 5170 traces live system calls but does not report the current set of open descriptors. du -sh /proc/5170 reports the aggregate size of the process's procfs directory, which is unrelated to open file descriptors.
Which ss invocation displays only listening TCP sockets along with the process that owns each socket, without resolving service or port names to text?#
Options
Show answer
The command ss -tlnp displays only listening TCP sockets, with numeric addresses and ports and the owning process for each socket. -t limits output to TCP, -l shows only LISTEN-state sockets, -n skips name resolution, and -p adds process information.
-t restricts output to TCP, -l shows only sockets in the LISTEN state, -n keeps addresses and ports numeric (no name lookup through DNS or /etc/services), and -p shows the owning process. ss -tp shows the owning process and would resolve names, but without -l it omits listening sockets and shows only non-listening TCP sockets. ss -tulnp adds -u, so it also includes UDP sockets and is not limited to TCP. ss -tan shows all TCP sockets in numeric form, both listening and non-listening, but has no -l filter and no -p, so it does not show the process owning each socket.
To remove all duplicate lines from a file using the sort and uniq pipeline, you must first _____ the file because uniq only collapses _____ duplicate lines.#
Show answer
To remove all duplicate lines from a file using the sort and uniq pipeline, you must first sort the file because uniq only collapses adjacent duplicate lines.
The uniq utility suppresses only adjacent matching lines. If duplicate lines are scattered throughout the file, uniq leaves them untouched. Piping the file through sort first groups identical lines together so that every duplicate becomes adjacent, allowing uniq to collapse them all — hence the canonical sort file | uniq pipeline.
In the Linux /proc filesystem, the file /proc/<pid>/_____ contains the full command-line arguments of the process as null-byte–separated strings, while /proc/<pid>/_____ lists the process's current memory-mapped regions (one per line, showing address ranges, permissions, offset, device, inode, and pathname).#
Show answer
In the Linux /proc filesystem, the file /proc/<pid>/**cmdline** contains the full command-line arguments of the process as null-byte–separated strings, while /proc/<pid>/**maps** lists the process's current memory-mapped regions (one per line, showing address ranges, permissions, offset, device, inode, and pathname).
Under /proc/<pid>/, the cmdline file holds the process's argv array with each argument separated by a null byte, and the maps file shows each virtual memory mapping the process currently holds — including shared libraries, the heap, the stack, and any file-backed mappings. These are kernel-provided pseudo-files, so they exist for any running process without needing external tools.
In tcpdump (libpcap filter syntax), what does the filter expression tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn match?#
Options
Show answer
The filter tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn matches TCP packets whose SYN flag is set and whose ACK flag is not set — i.e., initial connection-request SYNs. The bitmask isolates only the SYN and ACK bits; requiring the result to equal tcp-syn forces SYN on and ACK off, excluding SYN-ACK responses.
The expression tcp[tcpflags] & (tcp-syn|tcp-ack) applies a bitmask that isolates only the SYN and ACK bits from the TCP flags field. Comparing the masked result to tcp-syn (which has only the SYN bit set) means the SYN bit must be 1 and the ACK bit must be 0. This captures initial SYN packets (connection requests) and excludes SYN-ACK responses. The option "All TCP packets that have the SYN flag set, regardless of the ACK flag" is wrong because it would also match SYN+ACK packets where both flags are set. The option "TCP packets where either the SYN flag or the ACK flag is set" misreads the bitwise-AND as a logical OR, and the option "TCP packets where both the SYN flag and the ACK flag are set (SYN-ACK responses)" describes the opposite condition (both flags set).
Given the input string a::b::c, what is the output of the following command?#
Options
Show answer
The output is 3 b. Using awk -F':+' sets the field separator to a regular expression matching one or more consecutive colons, so a::b::c splits into three fields, making NF equal to 3 and $2 equal to b.
The -F':+' flag sets awk's field separator to the regular expression :+, which matches one or more consecutive colons. The double colons :: between each letter are treated as a single delimiter, so the record splits into three fields: a, b, and c. Therefore NF is 3 and $2 is b, producing the output 3 b. If -F':' (a literal single colon) were used instead, each colon would be a separate delimiter, producing empty fields and yielding NF=5 with an empty $2.
You inspect a running process with lsof -p <pid> and see file descriptor 3 open on /var/log/app.log with an offset of 5242880 (5 MB). You then run > /var/log/app.log from another shell to truncate the file to zero bytes. The process does not reopen the file; it continues calling write(3, buf, len). Where does the process's next write(3, ...) place its data, and what is the result?#
Options
Show answer
The write lands at offset 5242880, creating a sparse file. Truncating a file externally changes the inode size to zero but does not alter the offset stored in any process's open file description, so the process writes at its original position and leaves a hole from byte 0 to byte 5242879.
When a file is opened, the kernel creates an open file description (struct file) that stores the current offset independently of the inode's size field. External truncation via shell redirection (> /var/log/app.log) sets the inode size to 0 but does not touch any process's open file description or its stored offset. The lsof output confirms the offset is still 5242880, so the process's next write(3, ...) writes at byte 5242880, extending the file and leaving bytes 0–5242879 as a sparse hole (reading them returns zeros). The claim that external truncation resets the file offset stored in the open file description for every descriptor pointing to the file is wrong because truncation never modifies open file descriptions. The claim that truncation invalidates all existing file descriptors that reference the file's inode is wrong because truncation does not close or invalidate descriptors — only unlink + last-close or explicit close() does that. The claim that the kernel clamps the descriptor's offset to the file's current size before performing the write is wrong because the kernel does not clamp the offset to file size on write; it writes at the stored offset regardless.
Related interview questions
Job market
See linux salaries and hiring demand from live job postings.
The other 5 questions
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 5 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback