51 Shell Scripting Interview Questions And Answers 2024

1. What is Linux?

2. Difference between Linux and Unix?

3. What is a kernel?

4. What is an interpreter?

5. What is a compiler?

6. What is a shell?

7. What is CLI and GUI?

8.Why would we use CLI over GUI?

9. What is shell scripting?

10. What is the default login shell? How to change it?

11. What is the importance of shell scripting?

12. What are the various stages of the Linux process ?

13. What is the main difference between BASH and DOS?

14. What are the components of  Linux?

15. What is a root user?

16. What are the environmental variables?

17. What is LILO?

18. What are the different types of commonly used shells on a Linux system?

19. Which command is used to execute a shell file?

20. Name of editors which are available in almost all UNIX?

21. What is interactive and non-interactive shell?

22. What is the absolute and relative path?

23. How to create, read and delete files?

24. How to create and delete a directory?

25.  How to create multiple text files and directories?

26. What is the use of head and tail command?

27. How to find the current shell which you are using?

28.  How to find an available shell in your system?

29. How to create shortcuts in Linux?

30. How will you pass and access arguments to a script in Linux?

31. What is the significance of $#?

32. What is the difference between $* and @ ?

33.  Explain “s” permission bit in a file?

34.What are the different types of variables used in Shell Script?

35. What is the difference between = and ==?

36. What is the use of a pipe operator? How to execute multiple commands in one line?

37. What are the different modes of vi editors?

38. What is redirection?

39. How to find the status of the process?

40. How to check memory status?

41. How to debug a shell script?

42. Which command is used for comparing the string in the shell script?

43.Which four fundamental components of every file system?

44. What is the Crontab?

45.How many fields are present in a crontab file?

46.What are the two files of crontab command?

47. What are the different commands available to check the disk usage?

48. How to open a read-only file in the Shell?

49. How to find out how long the system has been running? 

50. How to connect to a remote server and execute some commands?

51.  How to connect to a database server from Linux? 

Shell Scripting Interview Questions And Answers

1. What is Linux?

Ans.Linux: Linux is an open-source, Unix-like operating system kernel that serves as the core of many Unix-like operating systems. Developed by Linus Torvalds in 1991, Linux is known for its stability, security, and scalability. It is widely used in server environments, embedded systems, and as the basis for various Linux distributions (distros) for desktop and other computing devices.

2. Difference between Linux and Unix?

Ans.While both Linux and Unix share similarities, there are some key differences:

  • Ownership and Licensing: Unix is typically proprietary and owned by various companies (e.g., AIX by IBM, Solaris by Oracle). Linux, on the other hand, is open-source, and its kernel is released under the GNU General Public License (GPL).
  • Development Model: Linux development follows a more collaborative, community-driven model, with contributions from a wide range of individuals and organizations. Unix systems are developed by specific companies.
  • Variety of Distributions: Linux is available in various distributions (distros) that package the Linux kernel with different software and configurations. Unix implementations may have less diversity.

3. What is a kernel?

Ans.Kernel: The kernel is the core component of an operating system that manages system resources, acts as an intermediary between the hardware and user-level applications, and provides essential services. It handles tasks like process scheduling, memory management, device drivers, and system calls.

4. What is an interpreter?

Ans.Interpreter: An interpreter is a program that directly executes instructions written in a programming or scripting language without the need for a separate compilation step. It translates and executes code line by line, interpreting the source code directly.

5. What is a compiler?

Ans.Compiler: A compiler is a program that translates the entire source code of a high-level programming language into machine code or an intermediate code. The resulting compiled code can be executed independently of the original source code.

6. What is a shell?

Shell: A shell is a command-line interface (CLI) that allows users to interact with the operating system by entering commands. It interprets user input and executes commands, acting as an interface between the user and the kernel. Common shells in Linux include Bash (Bourne Again SHell), Zsh, and Fish.

7. What is CLI and GUI?

Ans.

  • CLI (Command-Line Interface): CLI is a text-based interface where users interact with the system by typing commands into a terminal. It provides more control and is often preferred by experienced users and administrators.
  • GUI (Graphical User Interface): GUI uses graphical elements such as windows, icons, buttons, and menus to allow users to interact with the system. It is more user-friendly and is commonly used in desktop environments.

8. Why would we use CLI over GUI?

Ans.

Using CLI over GUI has several advantages:

  • Efficiency: CLI often allows for faster and more precise execution of commands.
  • Resource Usage: CLI consumes fewer system resources compared to GUI, making it suitable for servers or resource-constrained environments.
  • Scripting and Automation: CLI is scriptable, allowing users to automate repetitive tasks using shell scripts.
  • Remote Access: CLI can be accessed remotely through SSH, making it suitable for managing remote servers.

9. What is shell scripting?

Ans.Shell Scripting: Shell scripting involves writing scripts or programs using a shell (e.g., Bash) to automate tasks, execute commands in sequence, and perform various operations. Shell scripts are often used for system administration, file manipulation, and automation of repetitive tasks.

10. What is the default login shell? How to change it?

Ans.Default Login Shell: The default login shell is the shell that is launched when a user logs into the system. In many Linux systems, Bash is commonly set as the default login shell.

Changing Default Shell:
To change the default login shell for a user, the chsh (change shell) command can be used. For example:

$ chsh -s /bin/zsh

This command changes the default shell to Zsh.

11. What is the importance of shell scripting?

Importance of Shell Scripting:

  • Automation: Shell scripts automate repetitive tasks, saving time and reducing manual errors.
  • System Administration: Shell scripts are crucial for system administrators to manage and configure systems efficiently.
  • Batch Processing: Shell scripts can be scheduled to run at specific times, enabling batch processing of tasks.
  • Customization: Users can create custom scripts to tailor the system to their specific needs.
  • Troubleshooting: Shell scripts aid in diagnostics and troubleshooting by automating the collection of system information.

12. What are the various stages of the Linux process?

Ans.Various Stages of a Linux Process:

  1. Creation: A new process is created by the fork system call.
  2. Program Loading: The new process loads the program into its address space using the exec system call.
  3. Execution: The process executes the program’s instructions.
  4. Termination: The process terminates either voluntarily or due to an error.

13. What is the main difference between BASH and DOS?

Ans.BASH (Bourne Again SHell) vs. DOS (Disk Operating System):

  • Syntax: BASH uses a Unix-like syntax, while DOS uses a command prompt with a different syntax.
  • Functionality: BASH is a powerful shell with features like scripting, piping, and advanced commands. DOS has a more limited command set.
  • File System: BASH operates on a Unix-like file system with hierarchical directory structures. DOS has a simpler file system.
  • Scripting: BASH is a scripting language, allowing the creation of complex scripts. DOS commands are not as scriptable.
  • Case Sensitivity: BASH is case-sensitive, while DOS commands are typically case-insensitive.
  • Multitasking: BASH supports multitasking and concurrent processes. DOS is more limited in multitasking capabilities.

These differences reflect the distinct design philosophies of Unix/Linux and DOS operating systems.

Hridhya Manoj

Hello, I’m Hridhya Manoj. I’m passionate about technology and its ever-evolving landscape. With a deep love for writing and a curious mind, I enjoy translating complex concepts into understandable, engaging content. Let’s explore the world of tech together

Leave a Comment