Part #4: File Manipulation, System Logs, Security, and Miscellaneous (80–99 Questions)
In this part of the Linux Interview Handbook, we’ll focus on four key areas that build a strong foundation for Linux mastery: file manipulation and text processing, system logs, security essentials, and a set of miscellaneous commands.

Welcome to Part 4 of our Linux Interview Questions Series. In the previous part, we explored networking basics, package management, disk diagnostics, and performance monitoring tools.
In this part, we’ll dive into four practical areas: file manipulation and text processing, system logs, security essentials, and a handful of miscellaneous Linux commands.
You’ll learn how to work with text files, sort and filter data, track login attempts, block suspicious IPs, and gather key system details like architecture, default shell, and boot time.
These are everyday commands that every Linux user and system administrator should be comfortable with.
📂 File Manipulation and Text Processing
Linux provides powerful commands to work with text files, which are the backbone of configuration, logs, and scripts. Mastering these commands helps you quickly analyze data, automate tasks, and troubleshoot systems.
80. How can you count the number of lines, words, and characters in a file?
You can use the wc
(word count) command to quickly check the number of lines, words, and characters in a file.
wc filename
This will display three numbers: the first is the number of lines, the second is the number of words, and the third is the number of characters.
If you want to count only specific details, you can use options with wc
.
wc -l filename [count only lines]
wc -w filename [count only words]
wc -m filename [count only characters]
81. How do you display the first 10 lines of a file?
To display the first few lines of a file, you can use the head
command, which shows the first 10 lines by default.
head filename
If you want to see more than 10 lines, you can specify the number with the -n
option (or simply -
followed by the number).
For instance, to display the first 20 lines of a file, use:
head -20 filename
82. How do you display the last 10 lines of a file?
If you want to display the last few lines of a file, you can use the tail
command, which will show the last 10 lines of the file.
tail filename
If you want to see more lines, you can specify the number using the -n
option (or just a dash and number). For example, to display the last 20 lines, run:
tail -20 filename
Another useful option is monitoring a file in real time, which is especially handy for checking log files as they update.
tail -f filename
83. How do you sort lines in a file?
You can easily sort the lines of a file in alphabetical order using the sort
command.
sort filename
If you want to sort the lines in reverse (descending) order, you can use the -r
option:
sort -r filename
84. How do you remove duplicate lines from a file?
To remove duplicate lines from a file, you can use the uniq
command. However, uniq
only works on consecutive lines, so it’s best to sort the file first.
sort filename | uniq
If you also want to see how many times each line appeared, you can use the -c
option:
sort filename | uniq -c