blog
  • Blogs
    • Medium Articles
      • Linux
        • 40 Powerful Linux Networking Commands You Must Know.
        • These (Linux) VI Editor Shortcuts You Must Know
        • Bash/Linux Interview Questions for DevOps Engineers
        • Page 1
      • Git
        • 40 Powerful Git Commands Every Developer Should Know
        • 10 Git Best Practices That Every Developer Must Know
      • DevOps/SRE Interview Questions and Answers
        • Top DevOps/SRE Interview Questions and Answers on AWS VPC
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Terraform Best Practices
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Kubernetes Best Practices
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Dockerfiles
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Grafana
      • Installation
        • Docker Installation on Ubuntu 20/22
        • Install WireGuard VPN on Docker Compose
        • Install Redis on Docker Compose
        • Gravitee Docker Compose
      • Kubernetes Series 2025
        • Understanding Kubernetes: Part 1 -Control Plane
        • Understanding Kubernetes: Part 2 -Worker Node
        • Understanding Kubernetes: Part 3 -Pod
        • Understanding Kubernetes: Part 4-ReplicaSets
        • Understanding Kubernetes: Part 5 -Deployment
        • Understanding Kubernetes: Part 6 -DaemonSets
        • Understanding Kubernetes: Part 7 -StatefulSet
        • Understanding Kubernetes: Part 8 -ConfigMap
        • Understanding Kubernetes: Part 9 -Kubernetes Secret
        • Understanding Kubernetes: Part 10 -StorageClass
        • Understanding Kubernetes: Part 11 -Persistent Volume (PV)
        • Understanding Kubernetes: Part 12 -Persistent Volume Claim (PVC)
        • Understanding Kubernetes: Part 13 -Services
        • Understanding Kubernetes: Part 14 -ClusterIP Service
        • Understanding Kubernetes: Part 15 -NodePort Service
        • Understanding Kubernetes: Part 16 -Load Balancer Service
        • Understanding Kubernetes: Part 17 -Ingress
        • Understanding Kubernetes: Part 18 -Ingress Controller
        • Understanding Kubernetes: Part 19 -Headless Service
        • Understanding Kubernetes: Part 20-Network Policy
        • Understanding Kubernetes: Part 21 -CNI
        • Understanding Kubernetes: Part 22 Kubernetes Resource Requests & Limits
        • Understanding Kubernetes: Part 23 Node Selector
        • Understanding Kubernetes: Part 24 Taints and Tolerations
        • Understanding Kubernetes: Part 25 Affinity and Anti-Affinity
        • Understanding Kubernetes: Part 26 Preemption and Priority
        • Understanding Kubernetes: Part 27 Role and RoleBinding
        • Understanding Kubernetes: Part 28 ClusterRole and ClusterRoleBinding
        • Understanding Kubernetes: Part 29 Service Account
        • Understanding Kubernetes: Part 30 Horizontal Pod Autoscaler (HPA)
        • Understanding Kubernetes: Part 31 Vertical Pod Autoscaler (VPA)
        • Understanding Kubernetes: Part 33 Startup Probe
        • Understanding Kubernetes: Part 34 Liveness Probe
        • Understanding Kubernetes: Part 35 Readiness Probe
        • Understanding Kubernetes: Part 36 Container Network Interface (CNI)
        • Understanding Kubernetes: Part 37 Container Runtime Interface (CRI)
        • Understanding Kubernetes: Part 38 Container Storage Interface (CSI)
      • Cloudflare
        • Cloudflare Tunnel for Secure HTTP Routing
      • Nginx
        • Nginx use cases that every engineer must know
Powered by GitBook
On this page
  1. Blogs
  2. Medium Articles
  3. Linux

Bash/Linux Interview Questions for DevOps Engineers

PreviousThese (Linux) VI Editor Shortcuts You Must KnowNextPage 1

Last updated 2 months ago

Bash scripting is a superpower for engineers. Whether automating repetitive tasks, gluing together tools, or managing systems, Bash is always there, simple yet powerful.

Bash

1. What is the purpose of the shebang (#!) line?

It defines the interpreter that should execute the script. Example:

#!/bin/bash

2. How do you read command-line arguments in a shell script?

#!/bin/bash
echo "Script Name: $0"
echo "First Argument: $1"
echo "Total Arguments: $#"
echo "All Arguments: $@"
echo "Process ID: $$"
echo "Exit Status: $?"

3. What are the standard streams in Linux?

  • Standard Input (stdin)

  • Standard Output (stdout)

  • Standard Error (stderr)

4. What are the various types of variables used in shell scripting?

There are two types of variables used in shell scripting:

  • System-generated variables: These are created by the OS and can be viewed using the set command.

  • User-defined variables: Created by users and accessed using the echo command.

5. How do you check if a file exists using a conditional statement?

if [ -f /var/log/messages ]; then echo "File exists"; fi

6. How do you find and delete files older than 7 days?

find /path/to/directory -type f -mtime +7 -exec rm -f {} \;

7. What is crontab?

crontab (CRON Table) is used to schedule jobs to run at specific times. It allows automation of system tasks.

8. How do you debug a shell script?

  • Use set -x to enable debugging.

  • Use echo statements to track variable values and execution flow.

9. How do you rename all .txt files to .log in a directory?

for file in *.txt; do mv "$file" "${file%.txt}.log"; done

10. What are the default permissions of a file when it is created?

The default permissions are determined by the umask value. Typically, a new file has rw-rw-r-- (664) permissions.

11. What are the four stages of a Linux process?

  • Waiting: Process is waiting for a resource.

  • Running: Process is currently executing.

  • Stopped: Process execution has been stopped.

  • Zombie: Process has finished but still exists in the process table.

12. What is a metacharacter?

A metacharacter is a special character in the shell used for pattern matching. Example:

ls s*

Lists all files starting with ‘s’.

13. Difference between $@ and $*?

  • $* treats all arguments as a single string.

  • $@ treats each argument as a separate entity.

14. How would you check if a file named example exists in a specific path?

[ -e example ] && echo "File exists" || echo "File does not exist"

You can also use:

test -e example && echo "File exists" || echo "File does not exist"

15. How would you check disk usage using shell commands?

  • df -h: Shows available disk space.

  • du -sh /data01/*: Shows disk usage per directory.

  • dfspace: Provides space usage in megabytes.

16. What is the special shell variable $??

It stores the exit status of the last executed command.

cp file1 file2
if [ $? -eq 0 ]; then echo "Copy successful"; else echo "Copy failed"; fi

17. How to extract a substring from a variable?

variable="Her name is Jen, and she is a developer."
echo ${variable:12:6}  # Output: Jen, a

18. Difference between [[ $string == "efg*" ]] and [[ $string == efg* ]]?

  • [[ $string == efg* ]] checks if $string starts with "efg".

  • [[ $string == "efg*" ]] checks if $string is exactly "efg*".

19. How to list only filenames in a directory?

ls -1

To store the output in a variable:

filelist=$(ls -1 /somedir/)

20. What is the difference between soft and hard links?

  • Soft link (symbolic link): A pointer to the original file.

  • Hard link: A duplicate entry pointing to the same inode as the original file.

ln -s original_file soft_link
ln original_file hard_link

21. How do you replace a string in multiple files using sed?

sed -i 's/old_string/new_string/g' *.txt

22. What does grep -oP '\\d+' do?

It extracts numeric values from a string.

echo "Version=RevNo.201963" | grep -oP '\\d+'

Output: 201963

These questions cover key Bash and Linux concepts that every DevOps engineer should be familiar with. Mastering these will help you ace your next interview!

Happy scripting! 🖥️