Training Outcomes Within Your Budget!

We ensure quality, budget-alignment, and timely delivery by our expert instructors.

Share this Resource

Table of Contents

Top 40 UNIX Interview Questions and Answers

Navigating the world of technical interviews can be challenging, especially in specialised areas like UNIX systems. So, how do you prepare effectively? One way is by familiarising yourself with commonly asked UNIX Interview Questions. These questions often probe your understanding of UNIX architecture, shell scripting, file systems, and various command-line utilities. They give interviewers an insight into your practical skills and theoretical knowledge of UNIX environments. Read this blog to learn about the UNIX Interview Questions on basic UNIX commands, file and directory operation, and more and how to answer them. 

Table of Contents 

1) UNIX Interview Questions on basic UNIX commands 

2) UNIX Interview Questions on file and directory operations 

3) UNIX Interview Questions on UNIX permissions and ownership 

4) UNIX Interview Questions on process management 

5) UNIX Interview Questions on UNIX shell scripting 

6) UNIX Interview Questions on advanced UNIX concepts 

7) Conclusion 

UNIX Interview Questions on basic UNIX commands  

This section of the blog will expand on some commonly asked UNIX Commands interview questions. 

Q1) How do you list files in a directory?  

Ans: The ls command is fundamental in UNIX. By default, when executed, it displays the files and directories in the current directory. It provides a quick visual overview of directory contents, ensuring efficient navigation and file management. 

Q2) How can you list files with detailed information?  

Ans: To get a detailed listing of files, you can employ the ls -l command. This displays permissions, the number of links, file owner, file group, file size, and the time of the last modification. It's especially useful when monitoring file details and attributes. 

Q3) How do you navigate to parent or root directories?  

Ans: The command cd .. is employed to navigate to the parent directory, offering a step backwards in the directory tree. To directly navigate to the root directory, which is the base of the file system hierarchy, you use cd /. 

Q4) How do you view the contents of a file?  

Ans: The cat command, short for "concatenate and display", is versatile. Primarily, it is used to view the contents of a file, streaming its content to the standard output. This command provides a quick way to read small files or check file content without opening in an editor. 

Q5) How would you display the first 10 lines of a file?  

Ans: Utilising the head command proves beneficial for this. By default, executing head followed by a filename displays the file's initial ten lines. It's a great way to preview the beginning of large files or logs. 

Q6) How can you view the last lines of a file?  

Ans: The tail command serves this purpose efficiently. In its standard form, it exhibits the last ten lines of a file. It is particularly handy for real-time monitoring logs or checking recent file updates. 

Q7) How do you create an empty file in UNIX?  

Ans: The touch command is the tool of choice. When executed with a filename, e.g., touch filename.txt, it either creates an empty file or updates the timestamp of an existing one. It's a swift way to generate files or refresh their access times. 

Q8) How can you delete a file?  

Ans: To delete a file, the rm command is used. For example, executing rm filename.txt will remove the specified file after confirmation. Care should be exercised as this deletion is irreversible in standard file systems. 

Q9) How would you search for a specific pattern or word in a file?  

Ans: The grep command, derived from "Global Regular Expression Print", is indispensable. To search for a pattern within a file, you'd use grep "pattern" filename.txt. It scans the file line by line, printing lines that match the specified pattern – an essential tool for data parsing and content discovery. 

Q10) How can you search for files by name in a directory?  

Ans: The find command stands out for this task. For example, find . -name "example.txt" will search the current directory (denoted by ".") and its subdirectories for a file named "example.txt". This highly powerful command offers various flags and parameters for refined searching. 

Unlock the power of UNIX with our UNIX Fundamentals Course – join today! 

UNIX Interview Questions on file and directory operations  

This section of the blog will expand on some commonly asked UNIX Interview Questions and answers on file and directory operations.   

Q11) How do you create a directory in UNIX?  

Ans: In UNIX, the mkdir command is used to create directories. By executing mkdir directory_name, a new directory with the given name is created in the current location. The command is simple yet powerful, with options like -p, which allows the creation of nested directories in a single command. It's essential for organising files and ensuring structured data storage. 

Q12) How do you remove a directory?  

Ans: Directories can be removed using the rmdir command for empty directories. For instance, rmdir directory_name will remove the named directory, provided it's empty. However, if you need to remove a directory and its contents, the rm command with the -r (recursive) option, like rm -r directory_name, becomes useful. Caution is advised, as this operation is irreversible and can quickly delete large amounts of data. 

Q13) How do you move or rename a file or directory?  

Ans: The mv command serves the dual purpose of moving and renaming files or directories. To rename a file, mv old_filename new_filename is used. Similarly, to move a file to a different directory, the format is mv filename target_directory/. The same logic applies to directories. It’s a versatile command that aids in organising and re-structuring file locations and names. 

Q14) How can you copy files or directories?  

Ans: To duplicate files or directories, UNIX offers the cp command. For copying files, the syntax is cp source_file destination_directory/. If duplicating a directory, the -r option (meaning recursive) must be added, as in cp -r source_directory destination_directory/. This ensures all sub-files and sub-directories are replicated too. The cp command is fundamental when backing up data or creating duplicate research resources. 

Q15) How would you find the size of a file or directory?  

Ans: The du command, standing for "disk usage", can be employed to ascertain the size of files and directories. du -sh filename would display the size of a file, while du -sh directory_name reveals the total size of a directory. The -s provides a summary and -h displays sizes in a human-readable format (like KB, MB). It's an invaluable command for monitoring space utilisation and managing storage effectively. 

Q16) How can you create a symbolic link to a file or directory?  

Ans: Symbolic links (often called symlinks or soft links) can be crafted using the ln command with the -s option. The general form is ln -s target source_link. This creates a symbolic link named source_link that points to the target. Unlike hard links, symbolic links can reference directories or files across different file systems. They are especially useful for creating shortcuts or ensuring multiple paths to a single resource. 

Unlock the power of UNIX: Sign up for our UNIX Shell Programming Course today! 

UNIX Interview Questions on UNIX permissions and ownership  

This section of the blog will expand on some commonly asked UNIX Interview Questions and answers on permissions and ownership.   

Q17) How are UNIX file permissions represented?  

Ans: UNIX file permissions are typically represented using a combination of characters: r (read), w (write), and x (execute). These permissions are set for three different categories: the file's owner (user), the file's group (group), and others (other). A typical permission set might look like rw-r--r--, where the owner has read and write permissions, while the group and others have only read permissions. This symbolic notation can also be represented numerically, with read as 4, write as 2, and execute as 1, making the previous example 644. 

Q18) How do you change file permissions?  

Ans: The chmod command, short for "change mode", is employed to modify file or directory permissions. You can use symbolic or numerical notation with this command. For instance, chmod u+x filename adds execute permission for the user (owner), while chmod 755 filename sets permissions to rwxr-xr-x. The command offers flexibility, allowing users to control access to their files and directories precisely. 

Q19) How can you change the owner or group of a file?  

Ans: The chown command is used to change the owner of a file or directory. For instance, chown newowner filename would change the file's owner to "newowner". If you want to change both the owner and the group simultaneously, you will use a syntax like chown newowner:newgroup filename. For altering only the group, the chgrp command is used. As with most UNIX commands, care should be taken with these tools, ensuring that ownership is only granted to trusted users. 

Q20) What is the significance of the 'sticky bit' in permissions?  

Ans: The sticky bit is a permission setting that safeguards the files within a directory. When set on a directory, it ensures that only the owner of a file can either delete or rename the file, irrespective of the directory's permissions. This is especially useful in shared directories, like /tmp, preventing users from accidentally or maliciously deleting others' files. Symbolically, the sticky bit is represented as a t in the execute field for others, such as drwxrwxrwt. 

Q21) What's the difference between a hard link and a symbolic (or soft) link in terms of permissions?  

Ans: A hard link is an additional reference to the same inode on the disk, meaning it effectively "points" to the same data. Permissions changes on a hard link directly modify the original file since they reference the same data. Conversely, a symbolic (or soft) link is a separate file that points to another file's location. Permissions for the symlink are independent of the target file. Additionally, symlinks have their own set of permissions, but these largely affect the symlink itself and not the access to the target file. 

Q22) How can you set the setuid, setgid, and sticky bits using chmod? 

A: The setuid, setgid, and sticky bits are special permissions in UNIX that allow for enhanced security and functionality: 

a) setuid: When set on an executable file, it ensures that the program runs with the privileges of the owner of the file rather than the user who runs it. Using chmod, you can set the setuid bit with the symbol u+s or numerically as 4000. For instance, chmod u+s filename or chmod 4755 filename. 

b) setgid: This works similarly to setuid but for group permissions. It can be set on a file with g+s or 2000. When set on a directory, it ensures that files created within inherit the directory's group ownership. Use the command like chmod g+s directoryname or chmod 2755 directoryname. 

c) sticky bit: As mentioned earlier, it ensures that only the file owner can delete or rename files in a directory where it's set. You can set the sticky bit with o+t or numerically as 1000. For example, chmod o+t directoryname or chmod 1755 directoryname. 

Master UNIX administration with our expert-led Administrating UNIX Systems Course – join now! 

UNIX Interview Questions on process management  

This section of the blog will expand on some commonly asked UNIX Interview Questions and answers on process management.     

Q23) What is a 'process' in UNIX? 

Ans: In UNIX, a 'process' is a running instance of a program, possessing its memory space and assigned a unique process ID (PID). It can be in various states, like running, sleeping, or terminated, and is managed by the kernel. 

Q24) How can you view running processes? 

Ans: The ps command displays currently running processes, showing details like PID, terminal type, CPU time, and the command itself. For a comprehensive list, ps -ef or ps aux is commonly used. 

Q25) How can you send signals to processes? 

Ans: The kill command sends signals to processes, typically to terminate. For example, kill -9 PID sends the SIGKILL signal to terminate the process with the specified PID forcefully. 

Q26) Explain 'foreground' and 'background' processes. 

A: 'Foreground' processes run interactively, occupying the terminal until they are complete. Conversely, 'background' processes run behind the scenes, allowing terminal usage. Using & after a command starts it in the background. 

Q27) What is the 'nice' value in process management? 

Ans: The 'nice' value determines a process's priority. A process with a high nice value is 'nicer', getting less CPU time. Conversely, a lower nice value gets more CPU time. The nice command adjusts this value. 

Q28) How can you change the priority of a running process in UNIX? 

Ans: In UNIX, the renice command allows users to change the priority of a running process. Adjusting the 'nice' value influences the process's scheduling priority. For example, renice +5 PID would decrease the process's priority with the given PID, while renice -5 PID would increase its priority. Having the appropriate permissions is essential when trying to change the priority of processes not owned by the user. 

Unlock the power of Linux: Dive into our Linux Shell Programming Course today! 

UNIX Interview Questions on UNIX shell scripting  

This section of the blog will expand on some commonly asked UNIX Interview Questions and answers on shell scripting. 

Q29) What is a shell script in UNIX? 

Ans: A shell script is a sequence of commands that are stored in a file that the UNIX shell can execute. It automates repetitive tasks, enhances the command's capabilities, and can combine multiple utilities for complex operations. 

Q30) How do you make a shell script executable? 

Ans: To make a shell script executable, use the chmod command followed by +x. For instance, chmod +x scriptname.sh will grant execute permissions to the script. 

Q31) What's the significance of the '#!' (shebang) at the beginning of a script? 

Ans: The #! (shebang) at a script's start specifies the interpreter's path for executing the script. For example, #!/bin/bash instructs the system to use the Bash shell. 

Q32) How would you pass arguments to a shell script? 

Ans: Arguments can be passed directly after the script's name, like scriptname.sh arg1 arg2. Inside the script, $1, $2, etc., represent these arguments. 

Q33) What's the difference between '$#' and '$*' in shell scripting? 

Ans: In shell scripting, $# returns the number of arguments passed to a script, while $* displays all arguments as a single string. 

Q34) How can you check if a particular file exists in a shell script? 

Ans: To check if a file exists, use the -f test operator, as in [ -f filename ]. If true, it confirms the file's presence. 

UNIX Interview Questions on advanced UNIX concepts 

This section of the blog will expand on some commonly asked interview questions and answers on advanced UNIX concepts.  

Q35) What is the purpose of the 'cron' utility in UNIX? 

Ans: The cron utility in UNIX is a time-based job scheduler. It allows users and administrators to run scripts, commands, or jobs at predetermined intervals or specific times. Jobs can be scheduled to run by the minute, hour, month, week, or any combination thereof. Scheduled tasks are typically defined in a crontab file. The utility is indispensable for automating repetitive tasks, like taking regular backups, clearing temp directories, or fetching updates. 

Q36) Explain 'inodes' and their significance in UNIX.  

Ans: An inode (index node) in UNIX is a data structure that stores metadata about a file or directory except for its name or actual data. This metadata includes attributes like permissions, ownership, timestamps, and the location of data blocks. Every file or directory has a unique inode number within a filesystem. Inodes are significant because they underpin the UNIX filesystem's structure, allowing the system to manage and retrieve files efficiently. Operations that seem name-based, like renaming, often manipulate inodes behind the scenes. 

Q37) What is a 'daemon' in UNIX?  

Ans: A daemon is a background process or service that runs continuously, typically without any direct user interaction. Daemons perform tasks or provide services essential for the system's smooth running. Examples include sshd (secure shell daemon) for remote connections or crond for scheduling tasks. The naming convention for daemons usually ends in 'd'. They are crucial for server environments where services must run persistently, awaiting requests or performing regular duties. 

Q38) Describe 'pipes' and their usefulness in UNIX.  

Ans: 'Pipes', denoted by the | symbol, are a fundamental concept in UNIX that enables the output of one command to be fed as the input to another. This allows users to chain multiple commands together in sequence, effectively creating on-the-fly data processing streams. For instance, cat file.txt | grep "search_term" would display lines from file.txt containing "search_term". Pipes exemplify the UNIX philosophy of small, modular utilities that can be combined to produce complex results, promoting efficiency and reusability. 

Q39) How does UNIX handle process management and what is a 'zombie' process?  

Ans: UNIX employs a parent-child relationship for processes. When a process (parent) spawns another process (child), it's the parent's responsibility to retrieve the child's exit status. If the parent fails, the child remains in the process table, turning into a 'zombie' process. These zombies consume system resources without performing useful work. They can be identified using the ps command with statuses marked 'Z'. While individual zombies aren't harmful, they can clutter the process table in large numbers or if persistently generated, warranting intervention. 

Q40) What is 'IPC' in UNIX and why is it important? 

Ans: 'IPC' stands for Inter-Process Communication. It refers to the various mechanisms UNIX provides to allow processes to communicate with each other, either within the same system or across different systems. IPC mechanisms include pipes (both named and unnamed), message queues, semaphores, shared memory, and sockets. These tools are paramount because many applications and systems must coordinate tasks among multiple processes. 
 

UNIX Fundamental
 

Conclusion 

UNIX is a versatile Operating System with a rich history. By understanding the foundational concepts and commands, you are better equipped to tackle advanced tasks and troubleshooting in UNIX environments. We hope the aforementioned UNIX Interview Questions will be instrumental in your preparation for UNIX-related interviews or roles. 

Unlock your potential in the world of Linux with our wide range of Linux Training Courses. Explore our offerings and sign up today! 

Frequently Asked Questions

Upcoming IT Infrastructure & Networking Resources Batches & Dates

Date

building UNIX Fundamentals

Get A Quote

WHO WILL BE FUNDING THE COURSE?

cross

BIGGEST HALLOWEEN
SALE!

GET THE 40% EXTRA OFF!

red-starWHO WILL BE FUNDING THE COURSE?

close

close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.

close

close

Press esc to close

close close

Back to course information

Thank you for your enquiry!

One of our training experts will be in touch shortly to go overy your training requirements.

close close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.