Ramya Shankar | 10 Dec, 2022

Top Unix Interview Questions and Answers in 2024

Most interviewers look for candidates who have strong fundamental knowledge. If you are clear with the concepts, you can get through any trick questions or programming-related questions. Most of the time, the next questions are based on the previous answers, and that’s how interviewers build a conversation. Since Unix is a shell-based scripting language, you should know about bsh, csh, ksh, and bash. Interviewers also ask a lot about the Kernel and its purposes. Besides these two important concepts, Unix is all about commands and how to use the commands correctly.

Features of Unix

Before we get onto Unix interview questions, let us introduce Unix. It is useful if the interviewer asks you, ‘What is Unix?’. You can brief them on Unix and also give some features to impress them.

Unix is the most sought-after operating system because of its high reliability, scalability, and powerful features. Apple uses Unix, HP, AT&T, and many more big companies and backbone various data centers. The parent company of Unix is AT&T. Unix is free and easily accessible. Some features of Unix are:

  • Multiple users can get access by connecting to terminals.
  • High-level language, hence portable, and works across architectures.
  • Multitasking; many users can run various programs and processes parallely.
  • Users communicate with the system using Unix Shell translated to Kernel.
  • It follows a hierarchical file structure starting with a root directory represented by a slash (/).

Top Unix Interview Questions and Answers

We have answered the most commonly asked Unix interview questions below to help you get a fair idea of your interview. Not all questions will be asked in a single interview, but being prepared will help you better answer the questions. Some commonly asked Unix interview questions are:

1. What is the full form of UNIX?

Answer: Uniplexed Information & Computing System.

2. What are the common shells of Unix? Name their corresponding indicators.


Bourne Shell


Bourne Again shell


C Shell


Enhanced C shell


Z Shell


Korn Shell


3. What is a Unix shell?

Answer: Shell is a program or interface between system and user. In other words, it is the layer that understands both human and system language and executes commands entered by a user. It is also called a command interpreter.

4. What is the typical syntax of a UNIX command?

Answer: In general, the syntax of a UNIX command is:

<command> (-argument1) (-argument2) (-argument3) <filename>

Unix For Beginners

5. What does the symbol ‘*’ indicate to directories and files?

Answer: We use star character(*) for wildcards. Giving star after a command means including all the directories, folders, and files. For example, if you have to select all the files in a particular directory, you can give the command as:

ls *

6. Can you tell what a directory is? Command to create a Unix directory.

Answer: The directory is a structure that has a list of all the files inside it. The first directory is called the root directory. We represent the root using the slash (/) symbol. A directory can be created using the mkdir command by specifying the directory name:

mkdir dir1

7. What is the use of ls -l command?

Answer: ls -l is the long listing format to list all the information about the files in a directory. It displays all the information like the access, owner, timestamp, etc. Example:

dr-xr-xr-x 4 root root 4023 Mar 12 16:23 home

8. How to remove a directory in UNIX?

Answer: To remove a directory, use rmdir followed by the directory name. Example:

rmdir test

9. Name a few commands and their use?

Answer: Some common commands are:




restrict incoming messages by allowing or disallowing users to write on terminal.


to change the directory.


determines file type.


cuts selected fields of each line in the file.


counts the number of characters, words, lines.


opens vi editor.


file transfer protocol command.


print last few lines of a file/list.

10. What is the purpose of the kernel?

Answer: A kernel is the heart of Unix. It manages the hardware and software of the computer. The kernel manages the RAM to ensure all the programs run smoothly. It also manages access and use of different peripherals connected to the computers and manages processor time, task scheduling, and system files.

11. What does the command rm -r* do?

Answer: rm is to remove files

-r includes all the sub-directories of the current directory

* indicates all the files inside all the directories within

So, rm -r * removes all the files within the directory, including those in the sub-directories.

12. What is a Bourne shell? Explain with an example.

Answer: Bourne shell is a shell CLI for OS. It is represented by /bin/sh. Bourne shell executes each line of code till the end of the line (EOL) is found. Bourne shell doesn’t support arithmetic functions. Example:

echo “Hello, how are you?”

read response

13. What is the ‘cmp’ command? How is it different from ‘diff’?

Answer: cmp is used to compare files and gives out the exact line number & column number where the files differ.

diff is used to compare directories and list the different files and sub-directories in the directories being compared.

14. What is a shell script? Can you write a small program to print a message, “Good morning”?

Answer: A shell script is a program run by the Unix command line (CLI). The program to print ‘Good Morning’ is:

mymsg = Good morning

echo $mymsg

15. What does the setenv command do?

Answer: setenv defines the value of environment variables. It is a built-in function of csh (C shell). We can specify the argument (VAR), so it sets the particular environment variable. If no arguments are specified, setenv displays all the environment variables with their respective values.

16. How do you end a switch case statement in Unix?

Answer: It is done by reversing the letters of the word case, i.e., esac.

17. Give an example of a file system (hierarchy) in Unix.

Answer: Unix follows many standards for its file system. The first directory is ‘root’, represented with a forward slash (/). All the binaries that need to be available in single-user mode are contained in the /bin folder. Boot loaders like kernel, initrd are stored in /boot directory. Refer to the file hierarchy Wikipedia page for more.

18. What are the uses of head and tail commands?

Answer: The head command is used for printing the first n lines of a file onto the terminal:

head 7 test.txt

By default (i.e., when you don’t specify a number), ten lines are printed.

The tail command prints the last n lines of a file. By default, n is ten unless specified. We can specify more than one file, in which case the output is displayed along with the file name.

tail 15 test.txt


19. What will the following command do: $ grep “[^aeiou]” myfile

Answer: The command will match all lines that do not contain a vowel from the file ‘myfile’.

20. Explain the following piping command:

Answer: cat myfile | grep -i hi | sort – r

The command displays (cat) all the matches of ‘hi’ irrespective of the case (-i) and sorts the occurrences in the reverse order (-r).

21. What is the chmod command? What does ‘ch’ represent?

Answer: ch represents ‘change.’ chmod changes the access permissions for a file. We can represent permissions in octal digits 0-7 or letters. Example:

chmod 777 test.txt will give read, write, and execute permission for the file test.

chmod rwx test.txt does the same using letters.

22. What are the network commands you have used in Unix?

Answer: Some popular network commands are:




view network configuration


test network connection


get DNS lookup name


statistics of network connections, interface, routing tables


find the hostname (domain) and IP address

23. Differentiate between the absolute and relative path.

Answer: The absolute path is the complete path of a file or directory starting from its root directory. For example, /users/local/system

A relative path is the path from the current user directory and is not the complete path. It is the present working directory (PWD).

24. Explain pid with an example.

Answer: PID denotes process id. It is a unique id (number) that identifies all the processes running on the Unix system, whether foreground or background.

25. Describe inode.

Answer: The inode contains all the information about a file. It is a data structure that includes the file location on the disk, mode information, file size, device id, group id, access privileges, timestamps for file creation and modification, file protection flags.

26. If you have to change a Unix Directory, which command will you use?

Answer: The command chdir is used to change the Unix directory.

27. What are the uses of ‘mv’ and ‘cp’ commands?

Answer: cp copies files to a new directory location. The simple syntax is:

cp <source> <destination>. After executing the command, both the locations will have the same file.

mv is used to move/rename a file to another location (directory). The syntax is the same as cp:

mv <source> <destination>

The file will not be available in the source unless you specify backup options.

28. What are symbolic links?

Answer: A symbolic link has references to another directory or file. References are either relative (reference) or absolute (complete). The OS interprets symbolic links. The other file/directory is known as ‘target’. The symbolic link is created as:

ln –s <target> <link_name>

29. What are the permissions that can be given for a file? How can we change the permissions?

Answer: Unix files have three permission levels: write, execute and read. These are arranged in the order as <user permission>-<group permission>-<other permission>.

See Q21 use the chmod command.

30. Write the command to find the process that’s taking a lot of memory and kill that process.

Answer: The top command displays the pid, CPU usage, and other process details taking the maximum memory.

You can kill such a process using the kill command by passing the pid: kill <pid>

31. Do you know how to make changes to a large file without opening it?

Answer: For this, the sed command is used. For example, we want to replace the word ‘John’ with ‘Sam’. We can give the command as:

sed ‘s/John/Sam’ myfile.txt

32. What are the privileges of a superuser?

Answer: Superusers can access all the files and commands on the system without restriction. You can think of it as an admin account, which is above all the other accounts.

33. Can you list out a few shell responsibilities?

Answer: A shell is responsible for the following:

  • Environment control
  • I/O redirection
  • Program execution
  • Pipeline hookup
  • File name/variable substitution

34. How do you view information about a process in Unix?

Answer: You can just type ‘ps’ command.

35. Do you know about parsing? What is it?

Answer: The breaking of a command line into words by using spaces and delimiters is called parsing.

36. I want to search for the word ‘Morning’ in a file ignoring the case (example, considering both ‘m’ and ‘M’). For example, ‘morning’, ‘mORning’, ‘Morning’ etc. How can I do that?

Answer: Yes, by using the following command.

grep -vi morning myfile.txt

37. Explain what this command will do: sort file.txt | uniq > file2.txt

Answer: The command will sort the contents of the file and put the unique content into file2. Duplicate entries will not be copied to file2.

38. How do you get user inputs in Unix? Give an example.

Answer: Suppose we want to get a user’s name:

echo Hi, What is your name\?

read name

echo Welcome, $name

39. How do you get the current date? Can you customize how the date is printed?

Answer: We can get the current date by typing the ‘date’ command. Suppose we want the format as: day, month, date, year, time; we will specify the sequence as:

set ‘date’

echo $5 $3 $1 $2 $6 $4

40. What is a zombie process?

Answer: These are processes that do not take up any physical memory. Zombie processes have one or more of their listings still in the process table even after completion of execution.

41. What is swapping? Explain how a swapper works.

Answer: Swapping is a process where a complete process to be executed is moved to the main memory. The main memory capacity has to be more than the process size.

The swapper works based on a high scheduling priority base. It checks for sleeping processes. If there are not any, then ready-to-run processes are taken for swapping. To be swapped, the process should reside in the swapper for at least 2 seconds. If there are no available processes, the swapper goes into a wait state and waits until called by the Kernel (every second).

42. Explain what the ‘more’ command does.

Answer: It displays the contents of a file page by page instead of scrolling at once.

43. How can you check the disk capacity using the Unix command?

Answer: The disk capacity is checked using the ‘du’ command.

44. What is the fork() system call? How is it different from vfork()?

Answer: The fork() call creates a child process from an existing (parent) process. In the process, the kernel places a copy of the parent process’s address space into the child process. vfork() call is faster as it does not do the above.

45. Can you explain the page fault and kinds of page faults?.

Answer: It is a situation when a process tries to refer to a page. But the page is not there in the main memory. The two types are validity fault (whether the page is valid or not) and protection fault (whether it can be accessed).

46. Can you write a command to instruct the Unix system to restart after 30 minutes?

Answer: /sbin/shutdown -r+30. Here 30 indicates the minutes.

47. How does Unix represent hidden files?

Answer: Hidden files are represented using ‘.’ or dot before the file name. For example, .cshrc, .profile etc.

48. What is meant by the command: cd ../..

Answer: It means to change the directory to two directories back. For example, if you are on /usr/bin/sh, you will move to /usr.

49. Write the various commands to create new files in Unix?

Answer: We can do so using the command, $touch filename

We can also use the vi filename command.

50. Is there any difference between shell and environment variables? If yes, please tell me what it is.

Answer: Environment variables are global variables available to a program and its children. Shell variables are available only in the current shell. Once you exit the shell, the variables are lost.


One of the key points to clear an interview is to be confident and accept what you don’t know. Interviewers don’t want you to know everything or be perfect. Just don’t beat around the bush and explain what you know thoroughly. Learn more about Unix through our list of courses and tutorials. Happy preparing!

People are also reading:

By Ramya Shankar

A cheerful, full of life and vibrant person, I hold a lot of dreams that I want to fulfill on my own. My passion for writing started with small diary entries and travel blogs, after which I have moved on to writing well-researched technical content. I find it fascinating to blend thoughts and research and shape them into something beautiful through my writing.

View all post by the author

Subscribe to our Newsletter for Articles, News, & Jobs.

I accept the Terms and Conditions.

Disclosure: Hackr.io is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

In this article

Learn More

Please login to leave comments