Interview Q&A / Linux & Shell
Linux & Shell interview questions
Permissions, processes, pipes and the commands you are expected to know cold.
Prefer rapid revision? Practise Linux & Shell short interview answers →
- How do file permissions work in Linux, and what do chmod 755 and 644 mean?
Every file has read, write and execute permissions for three groups of people - the owner, the group and everyone else. chmod changes them; 755 means the owner can do everything while others can only read and execute, and 644 means the owner can read and write while others can only read.
BeginnerIn-depth3 min read - How do you search for text and files in Linux using grep and find?
grep searches inside files for lines matching a pattern, for example grep -rn "error" logs/. find searches the directory tree for files by name, type, size or age, for example find . -name "*.log" -mtime -1. They are often combined to search text inside a chosen set of files.
BeginnerIn-depth2 min read - What are environment variables in Linux, and what does the PATH variable do?
Environment variables are named values (like HOME, USER or PATH) that every process inherits from its parent. PATH is a colon-separated list of directories the shell searches, in order, to find a command you type, so you can run python3 instead of /usr/bin/python3.
BeginnerIn-depth3 min read - What is cron, and how do you read crontab syntax?
cron is a Linux service that runs commands on a schedule. Each crontab line has five time fields - minute, hour, day of month, month and day of week - followed by the command, so "30 2 * * 1-5 /home/ravi/backup.sh" runs the backup at 2:30 AM every Monday to Friday.
BeginnerIn-depth3 min read - What is the difference between >, >>, 2>&1 and | in the Linux shell?
The > operator writes a command's output to a file and overwrites it, >> appends to the file, 2>&1 sends error output to the same place as normal output, and the pipe | feeds one command's output straight into the next command's input.
BeginnerIn-depth3 min read - How do you check disk space and memory usage on a Linux server?
Use df -h to see free space on each mounted file system, du -sh to see how much space a folder takes, and free -h to see RAM and swap. In free, look at the "available" column, not "free", because Linux uses spare RAM as disk cache and gives it back when programs need it.
IntermediateIn-depth3 min read - What is the difference between a hard link and a soft link in Linux?
A hard link is another name for the same file on disk (the same inode), so the data stays as long as any name exists. A soft (symbolic) link is a small separate file that stores a path to the target; it breaks if the target is moved or deleted, but it can point to directories and across file systems.
IntermediateIn-depth3 min read - How do you find and stop a process in Linux, and what is the difference between SIGTERM and SIGKILL?
Use ps or top to find the process ID, then kill to send it a signal. SIGTERM (15, the default) politely asks the process to exit so it can clean up, while SIGKILL (9) makes the kernel end it immediately and cannot be caught or ignored.
AdvancedIn-depth3 min read