Linux Interview Question and Answers

  1. How do you check available memory in Linux?
    • Description: The free command shows the amount of free and used memory in your system.
    • Example: free -h
      • -h makes the output human-readable by using units like MB and GB.
  2. What are some common Linux distributions?
    • Description: Linux distributions are different versions of the Linux operating system, each with unique features and software.
    • Examples: Ubuntu, Debian, Fedora, CentOS, Red Hat Enterprise Linux.
  3. What is a symbolic link?
    • Description: A symbolic link is a type of file that acts as a shortcut to another file or directory.
    • Example: ln -s /path/to/original /path/to/symlink
      • This creates a symlink named symlink pointing to original.
  4. How do you find files on a Linux system?
    • Description: The find command searches for files and directories based on specific criteria.
    • Example: find /home/user -name "*.txt"
      • This searches for all .txt files in the /home/user directory.
  5. What does the grep command do?
    • Description: grep searches for lines in files that match a given pattern.
    • Example: grep "search_term" filename.txt
      • This finds and displays lines in filename.txt that contain “search_term”.
  6. How can you start or stop services in Linux?
    • Description: Services can be managed using systemctl in systems with systemd.
    • Examples: systemctl start nginx (starts the nginx service) and systemctl stop nginx (stops the nginx service).
  7. What is SSH and how is it used?
    • Description: SSH (Secure Shell) provides a secure way to access and manage remote computers over an encrypted connection.
    • Example: ssh user@remote_host
      • This command connects to remote_host using the username user.
  8. How do you check disk usage in Linux?
    • Description: The df command shows how much disk space is used and available on file systems.
    • Example: df -h
      • -h provides human-readable output with sizes in KB, MB, or GB.
  9. What is the role of the Linux kernel?
    • Description: The kernel is the core of the Linux operating system, managing hardware resources and system services.
  10. How do you change file permissions in Linux?
    • Description: The chmod command changes who can read, write, or execute a file.
    • Example: chmod 755 filename
      • This gives the owner full permissions and others read and execute permissions.
  11. What is the purpose of the tar command?
    • Description: tar is used to create, extract, and manage archive files.
    • Example: tar -cvf archive.tar /path/to/directory
      • This creates an archive named archive.tar containing the contents of /path/to/directory.
  12. How do you compress and decompress files?
    • Description: Use gzip to compress files and gunzip to decompress them.
    • Examples:
      • Compress: gzip file.txt
      • Decompress: gunzip file.txt.gz
  13. What is the purpose of the cron daemon?
    • Description: cron schedules tasks to run automatically at specified times or intervals.
    • Example: To run a script every day at midnight, you might add 0 0 * * * /path/to/script.sh to the crontab.
  14. How do you monitor system processes and resources?
    • Description: The top command provides a real-time overview of system processes and resource usage.
    • Example: top
      • Displays a dynamic list of running processes and system resource usage.
  15. What is a firewall in Linux?
    • Description: A firewall controls network traffic based on rules to protect your system from unauthorized access.
    • Example: Using iptables to block traffic on port 22: iptables -A INPUT -p tcp --dport 22 -j DROP.
  16. How do you create a new user in Linux?
    • Description: The useradd command creates a new user account.
    • Example: useradd -m newuser
      • Creates a new user named newuser with a home directory.
  17. How do you check the system’s IP address?
    • Description: The ip addr command shows IP addresses assigned to network interfaces.
    • Example: ip addr show
      • Lists all network interfaces and their IP addresses.
  18. How do you kill a process in Linux?
    • Description: Use kill to terminate processes using their PID, or killall to terminate by process name.
    • Examples:
      • kill 1234 (kills the process with PID 1234)
      • killall firefox (kills all processes named firefox)
  19. What is the purpose of the iptables command?
    • Description: iptables configures the Linux kernel firewall to manage network traffic.
    • Example: iptables -A INPUT -p tcp --dport 80 -j ACCEPT
      • Allows incoming traffic on port 80.
  20. How do you mount a filesystem in Linux?
    • Description: The mount command attaches a filesystem to a directory, making it accessible.
    • Example: mount /dev/sdX1 /mnt
      • Mounts the filesystem on /dev/sdX1 to the /mnt directory.
  21. What does the rsync command do?
    • Description: rsync synchronizes files and directories between locations efficiently.
    • Example: rsync -av /source/ /destination/
      • Copies files from /source/ to /destination/, preserving attributes.
  22. How do you view hardware information in Linux?
    • Description: The lshw command provides detailed information about your system’s hardware.
    • Example: lshw -short
      • Displays a summary of hardware components.
  23. What is a shell in Linux?
    • Description: The shell is a command-line interface for interacting with the operating system by typing commands.
    • Example: bash is a common shell used in Linux systems.
  24. How do you check network configuration?
    • Description: The ifconfig command (deprecated) and ip command display network settings.
    • Example: ip a
      • Shows details of all network interfaces.
  25. What does the chroot command do?
    • Description: chroot changes the root directory for a process, isolating it in a new environment.
    • Example: chroot /path/to/newroot /bin/bash
      • Changes the root directory to /path/to/newroot and starts a bash shell.
  26. How do you search recursively for a string in files?
    • Description: Use grep with the -r option to search for a string in all files within a directory.
    • Example: grep -r "search_term" /path/to/directory
      • Searches for “search_term” in all files under /path/to/directory.
  27. What is the purpose of the find command?
    • Description: find searches for files and directories based on various criteria.
    • Example: find /home/user -type f -name "*.jpg"
      • Finds all .jpg files in the /home/user directory.
  28. How do you check CPU usage in Linux?
    • Description: Use top, htop, or mpstat to view CPU usage and process information.
    • Example: top
      • Displays a dynamic, real-time list of processes and CPU usage.
  29. How do you check file permissions in Linux?
    • Description: Use ls -l to display file permissions along with other file details.
    • Example: ls -l filename
      • Shows permissions, ownership, and other details of filename.
  30. What is the role of the grep command?
    • Description: grep searches for lines in files that match a specified pattern and outputs them.
    • Example: grep "error" logfile.txt
      • Finds and displays lines in logfile.txt containing the word “error”.