UNIX has been around since the 1960s, and due to its security and portability, it has been widely adopted across various systems and servers and is also the foundation of various modern operating systems such as macOS and Linux.
UNIX interview questions are often asked in technical interviews for roles such as systems administrator, DevOps engineer, and system architect. In this article, we shall explore the top 30 UNIX interview questions to help you build confidence and master UNIX fundamentals and advanced concepts.
Table of Contents
Basic UNIX Commands Interview Questions
Let’s start with some basic UNIX command interview questions before we delve into more complex topics.
1. What is UNIX, and how is it different from other operating systems?
UNIX, developed in an AT&T Bell lab in the 1970s, is a multiuser & multitasking operating system that is widely adopted and is the foundation of popular, modern operating systems such as macOS and Linux. Its unique command line interface and portability across various hardware makes it a flexible and scalable choice for various applications and systems.
2. What are the key features of UNIX?
UNIX has many great features, making it an ideal choice for developers. One of the main features of UNIX is that it supports multiple users and multiple processes at the same time, making it ideal for shared systems and servers. UNIX has a secure and comprehensible tree-like file structure that offers superior permission management capabilities. File permissions are maintained through group and user permission separation, which facilitates system security and integrity.
The feature that stands out from the modern operating systems that we know is the command-line interface, which allows for shell scripts, used to automate tasks and reduce manual effort.
3. How do you list files in a directory and view detailed information?
The ls command is used to list the files in a directory. You can also use ls -l to display a more detailed report containing information like file permissions, file’s owner, file size, and much more.
4. How do you navigate between directories in UNIX?
Due to UNIX’s command-line interface, navigation between directories is done by using UNIX commands. More specifically, the cd command. You can add suffixes to the command to access additional functions.
- cd ~ takes you to the home directory
- cd .. moves up one level to the parent directory
- cd / takes you to the root directory
5. How do you view the contents of a file (head, tail, cat)?
There are several commands you can use to view the contents of a file. The cat command displays the entire contents of the file at once, the head command displays the first 10 lines of the file, and the tail command displays the last 10 lines of the file. All three of the commands are used by developers based on the requirement at hand.
6. What does the rm -r * command do? Why is it dangerous?
The rm -r* command recursively deletes all files and directories in the current working directory. Once the command is run, it does not ask for confirmation before deleting the files and making them unrecoverable, which makes it dangerous.
7. How do you find hidden files in UNIX?
Hidden files in UNIX can be listed using the ls -a command, which will list all the files in the current directory, including hidden files.
File and Directory Operations: UNIX Interview Questions and Answers
Now that we have covered the basic UNIX interview questions. The following UNIX interview questions and answers delve a little deeper into file and directory operations.
8. How do you create, rename, copy, and delete files/directories in UNIX?
Since UNIX is command-line oriented, functions like create, rename, copy, and delete are executed through various commands such as:
Command |
Action |
touch |
Creates a new file |
mkdir |
Creates a new directory |
mv |
Moves or renames files or directories |
cp |
Copies files (cp) or directories (cp -r) |
rm |
Removes a file |
rm -r |
Recursively deletes a directory and its contents |
9. What is a link in UNIX? Differentiate hard link vs soft link.
A link in UNIX is nothing but a reference to a file. There are two kinds of links in UNIX.
A hard link points directly to the data on the disc by referencing its inode, which allows the link to retain the data even if the original file name is deleted. However, hard links cannot span across different file systems or reference directories.. This is where soft links come in handy. They act as more of a shortcut by pointing to the filename instead of the file’s data directly. If the original file is removed, the link breaks.
10. What are inodes and their significance in UNIX file systems?
In UNIX file systems, an inode(Index Node) is a data structure that stores the metadata about files or directories. Each file in the file structure is represented by an inode that contains information about the file, such as the file’s size, owner, permissions, timestamps (created, modified, accessed), and pointers to the actual data blocks on disk. It is to be noted that it does not store the file’s name or directory path, which is stored separately in directory entries, which map filenames to an inode.
11. What is the difference between absolute and relative paths?
In UNIX, the location of files can be specified by absolute or relative paths. An absolute path defines the full path of a file starting from the root directory “/”. A relative path specifies the location of the file or directory in relation to the current working directory and therefore does not start with the root.
12. How do you find the size of a file or directory?
To find the size of a file or directory in UNIX, you can use the ls or du command. While the ls -l displays file size in bytes, du -sh will give you a more readable format.
Permissions and Ownership: UNIX Interview Questions
Permission and ownership management in UNIX is a more advanced concept and one of its main features. Let’s have a look at some of the most popular interview questions.
13. How do you change ownership and permissions of a file/directory?
File permissions in UNIX define the actions that a user can perform. They are divided into 3 categories: owner, group, and others. Each category can perform the following functions: read, write, and execute. The uses of the chmod, chown, and chgrp commands are as follows:
Command |
Description |
chmod |
Changes file or directory permissions |
chown |
Changes the owner of the file |
chgrp |
Changes group of the file |
14. What is the sticky bit, setuid, and setgid in UNIX?
Sticky bit, setuid, and setgid are special permissions bits in UNIX that provide additional control over files and directories on top of the read, write, and execute functions.
The setuid(Set User ID) permission allows an executable file to run with the permission of the file’s owner rather than the user executing it. While the setgid (Set Group ID) works similarly, it provides the permissions of the group instead. The sticky bit is used mainly for temporary files, which, when set, only allows the file’s owner, the directory’s owner, or the root user to delete or rename the file.
15. What happens if you remove execute permission from a directory in UNIX?
Removing execute permissions from a directory in UNIX will prevent the user from accessing the files within that directory, even if they have read and write permissions.
16. What command would you use to find all files owned by a specific user?
In UNIX, you can use the find / -user username command to display all the files owned by the “username”.
Process and Memory Management: UNIX Command Interview Questions for Experienced
Process and memory management is a fundamental skill that UNIX system administrators must master. It helps in maintaining the performance of an application or server. These UNIX interview questions and answers are designed to help you understand how and when memory is used in UNIX systems and how to manage processes.
17. What is a process in UNIX?
A process in UNIX is nothing more than an active instance of a program. When a user runs a script, command, or application, a new process with a unique process ID is created. It operates independently with its own memory, execution state, and other system resources. You can use UNIX commands such as kill, top, nice, and ps to manage these processes.
18. How do you list and kill running processes (ps, kill)?
Processes are managed through the command line in UNIX. The ps command provides the user with information about a process, like process ID, the user running the process, and CPU/memory usage. The kill command is used to send a request to the process usually used to end it.
19. What is a Zombie process, and how do you identify it?
When a process is completed in UNIX but still exists as an entry in the process table, it is known as a zombie process. Zombie processes do not consume CPU or memory and can be identified by using the ps command.
20. What is the fork() system call and its purpose?
The fork() system call is used in UNIX to duplicate the current process. Using the fork() creates a child process which is identical to the parent(current process), both of which continue to run independently after the fork.
21. What is the difference between swapping and paging?
While both swapping and paging are memory management techniques in UNIX, they differ in functionality. Swapping is the process of moving entire processes from the main memory to the disc, and paging involves moving individual pages within a process.
UNIX Shell Scripting Interview Questions
Shell scripting is a foundational feature of UNIX-based systems and allows the user to run multiple commands at the same time, enabling them to automate repetitive and/or complicated tasks by running one file. Let’s take a look at some of the more popular UNIX shell scripting interview questions to get a better understanding.
22. What is a shell script, and how is it executed in UNIX?
A shell script is a text file that contains a series of commands that will be executed in sequence once run. It provides developers with an easier way to perform repetitive and complex tasks. When a script is executed, the UNIX shell reads and executes each command line by line.
23. What does the #! (shebang) Signify at the start of a script?
The #! (shebang) is used at the start of a shell script to indicate the specific interpreter to be used to run the script. For example, “/usr/bin/python” can be used to run the shell script using the Python interpreter. Please note that the location of the interpreter may differ on your machine.
24. What’s the difference between $* and $# in shell scripting?
$ followed by special characters in UNIX is a special variable used to provide additional information about the script’s execution. $* represents all the arguments passed to the script as a single string. It treats all the arguments as one word, while $# returns the number of arguments passed to the script.
25. How do you check if a file exists within a shell script?
The test command in UNIX is used to check if a file exists within a shell script, which evaluates conditional expressions and returns a status code that can be used in an if statement. You can also use other test flags for more specific checks:
- -f: checks if it’s a regular file
- -d: checks if it’s a directory
- -r: checks if the file is readable
- -w: checks if the file is writable
- -x: checks if the file is executable
26. What are shell variables, and how are they used?
Shell variables are used in UNIX shell scripts to store data from strings, numbers, and file paths. They allow scripts to be dynamic and reusable. You can declare a shell variable like so:
name="intellipaat"
number=”10”
Networking and Communication Commands
UNIX is widely used in servers, and so networking UNIX command interview questions are often asked in UNIX system administrator technical interviews. Mastering these commands and concepts will help you handle server and network requests with ease.
27. How do you check if a remote host is reachable from your UNIX system?
The ping command in UNIX is used to test network connectivity in a UNIX-based system. It helps verify network connectivity or troubleshoot issues.
28. What is the difference between scp and ftp?
scp (Secure Copy) uses SSH to securely transfer files between systems, ensuring encryption. ftp (File Transfer Protocol) is older, not encrypted by default, and requires an FTP server. SCP is generally preferred for secure transfers.
29. How do you display open network connections and listening ports?
Use the netstat -an or ss -tuln command. These show active connections, listening ports, and associated protocols (TCP/UDP), which are useful for diagnosing network services or issues.
30. How do you transfer a file from your local UNIX machine to a remote server?
You can use the scp command:
scp /path/to/file username@remote_host:/destination/path
This securely copies the file over SSH. You’ll need credentials or SSH key access to the remote server.
31. How can you test if a specific port is open on a remote system?
Use the telnet or nc (netcat) command:
telnet remote_host 80
nc -zv remote_host 22
These commands attempt to connect to the specified port and report if it’s open or closed, helping diagnose firewall or service availability issues.
Advanced UNIX Interview Questions
Here are some more advanced UNIX command interview questions for experienced professionals. These questions are frequently asked for senior-level roles, and mastering them will also help gain confidence and a deeper understanding of UNIX and its functionalities.
32. What is piping and redirection in UNIX?
Piping and redirection are used in UNIX to control the flow of data between commands and files. Redirection (>) is used to change the input/output behavior of commands. For example, using ls > files.txt outputs redirects the output to a file.
Piping(|) is used to connect the output of a command to the input of another, allowing complex operations to be built from simple commands.
33. What is the use of cron, and how do you schedule jobs?
Cron is a time-based scheduler in UNIX used to automate recurring tasks that are to be executed at recurring intervals. It is mostly used for tasks such as system backups or maintenance routines. To schedule a cron job, you need to add an entry to your crontab file using the -e command.
34. What is a daemon in UNIX?
Daemons in UNIX are processes that run in the background with minimal to no user intervention. They usually start at system boot and continue to run silently in the background until the system shuts down. Daemons can be used to handle tasks such as logging, networking, and other system services.
35. Explain the UNIX system boot process.
The UNIX system boot process is a sequence of steps that the system follows to get it from boot up to a usable and stable state. The steps are as follows:
- BIOS/UEFI Initialization
- Bootloader Execution
- Kernel Loading
- Init/System Initialization
- Runlevel/Target Configuration
- Login Prompt
Each stage is critical for ensuring system stability, service availability, and user accessibility.
36. What are system calls, and how are they different from library functions?
In UNIX, a system call is how a program asks the operating system to do something that it can’t do on its own, like reading a file, creating a new process, or accessing hardware. Since regular programs run in user space and the operating system works in kernel space, system calls act as a bridge between the two. Examples include read(), write(), fork(), and exec().
On the other hand, library functions are higher-level functions provided by programming libraries like the C standard library that make it easier to get things done. For example, when you use printf() to print something to the screen, it might eventually use the write() system call behind the scenes, but you don’t have to worry about the details.
Conclusion
Mastering UNIX is much more than memorizing UNIX commands. You need a solid understanding of how the system operates, how to automate tasks effectively, and the ability to troubleshoot issues with confidence. The questions covered in this blog highlight some of the most important concepts and practical skills that employers look for in UNIX professionals. Whether you’re preparing for a technical interview or just brushing up your knowledge, these topics are essential for both beginners and experienced administrators.