Linux Admin Interview Questions and Answers

Find 100+ Linux Admin interview questions and answers to assess candidates' skills in server management, user permissions, shell scripting, networking, and system security.
By
WeCP Team

As modern IT infrastructure increasingly relies on Linux-based systems, recruiters must identify Linux Administrators who can ensure system stability, security, and performance. From managing user access and permissions to configuring servers and automating tasks, Linux Admins play a critical role in maintaining enterprise environments.

This resource, "100+ Linux Admin Interview Questions and Answers," is tailored for recruiters to simplify the evaluation process. It covers everything from basic command-line operations to advanced system administration, including shell scripting, cron jobs, network configuration, and security hardening.

Whether hiring System Administrators, DevOps Engineers, or Infrastructure Specialists, this guide enables you to assess a candidate’s:

  • Core Linux Knowledge: Understanding of file systems, permissions, user/group management, and process control.
  • Advanced Skills: Proficiency in shell scripting, system boot process, package management, and kernel tuning.
  • Real-World Proficiency: Ability to troubleshoot services, manage backups, configure firewalls (iptables), and monitor system health using tools like top, netstat, and journalctl.

For a streamlined assessment process, consider platforms like WeCP, which allow you to:

Create customized Linux Admin assessments for various distributions like Ubuntu, CentOS, or RHEL.
Include hands-on terminal-based tasks and scripting exercises.
Proctor exams remotely with integrity safeguards.
Use AI-powered analysis to auto-evaluate scripts, commands, and config scenarios.

Save time, boost hiring quality, and confidently recruit Linux Administrators who can keep your systems secure, stable, and production-ready from day one.

Linux Admin Interview Questions

Beginner's Level Interview Question

  1. What is Linux?
  2. What are the different types of Linux distributions?
  3. What is the Linux kernel?
  4. What is a shell in Linux?
  5. What are the different types of shells available in Linux?
  6. How do you list all files in a directory in Linux?
  7. What does the chmod command do?
  8. What is the difference between a hard link and a soft link?
  9. What are the basic Linux file permissions?
  10. What is the ls command used for?
  11. How do you check the current working directory in Linux?
  12. What is the pwd command used for?
  13. How do you change directories in Linux using the cd command?
  14. How do you copy a file in Linux?
  15. How do you move a file in Linux?
  16. How do you delete a file in Linux?
  17. What is a process in Linux?
  18. How do you check running processes in Linux?
  19. What is the top command used for?
  20. How do you kill a process in Linux?
  21. What is the difference between kill and killall?
  22. What is the grep command used for in Linux?
  23. How do you redirect output to a file in Linux?
  24. What is the echo command used for?
  25. What is the cat command used for in Linux?
  26. What is the purpose of the /etc/passwd file?
  27. How do you create a new user in Linux?
  28. What is the purpose of the /etc/group file?
  29. How do you check the free disk space in Linux?
  30. What is the df command used for?
  31. What is the du command used for in Linux?
  32. How do you check the memory usage in Linux?
  33. What is the free command used for?
  34. How do you check the system's uptime?
  35. What is the uptime command used for?
  36. What is the man command in Linux?
  37. What is the whoami command used for?
  38. How do you search for a file in Linux?
  39. What is the find command used for?
  40. What is the role of root user in Linux?

Intermediate Level Interview Question

  1. What is a package manager in Linux? Can you name a few package managers?
  2. What is the difference between yum and apt-get?
  3. How do you install software in Linux using the package manager?
  4. How can you check which packages are installed on a system?
  5. What is the purpose of /etc/fstab file?
  6. What is the purpose of the dmesg command in Linux?
  7. What is a swap partition in Linux and why is it used?
  8. How do you manage system services in Linux using systemd?
  9. What is the systemctl command used for?
  10. How do you start and stop services using systemctl?
  11. How do you view the status of a service using systemctl?
  12. What is the difference between a system service and a user service in systemd?
  13. How do you configure a static IP address in Linux?
  14. What is the /etc/network/interfaces file used for?
  15. How do you check the network configuration in Linux?
  16. What is the ifconfig command used for in Linux?
  17. What is the purpose of the /etc/hostname file?
  18. How do you configure a hostname in Linux?
  19. What is the purpose of the iptables command?
  20. How do you open or close ports in Linux using iptables?
  21. What is SELinux? How do you check its status?
  22. How do you disable SELinux?
  23. How can you set up cron jobs in Linux?
  24. What is the crontab file and how is it used?
  25. How do you configure a cron job to run every day at midnight?
  26. What is the ps command used for in Linux?
  27. How do you monitor disk usage over time in Linux?
  28. What is the iostat command used for?
  29. How do you back up files in Linux?
  30. What is the rsync command used for?
  31. How do you check and repair a filesystem in Linux?
  32. What is the fsck command used for?
  33. What is a daemon in Linux?
  34. How do you find logs in Linux? Where are the log files stored?
  35. What is the /var/log directory used for?
  36. What is the tail command used for in Linux?
  37. What is the head command used for in Linux?
  38. How do you search for specific strings in files?
  39. What is the purpose of the /tmp directory in Linux?
  40. How do you check the load on a Linux system?

Experienced Level Interview Question

  1. What is the difference between hard and soft mounts in Linux?
  2. Explain the boot process in Linux.
  3. What are the key differences between a physical machine and a virtual machine in Linux?
  4. How would you troubleshoot a network connectivity issue in Linux?
  5. What is a Linux LVM (Logical Volume Manager)?
  6. How do you create and manage Logical Volumes in Linux?
  7. How do you configure RAID in Linux?
  8. What is the purpose of the /proc directory in Linux?
  9. How do you secure a Linux server?
  10. What are SSH keys, and how do you configure them?
  11. How do you configure a firewall in Linux using ufw or iptables?
  12. How would you implement an automated backup solution in Linux?
  13. What is the role of journalctl in systemd logging?
  14. What are namespaces in Linux?
  15. How do you implement user authentication and authorization in Linux?
  16. What is the purpose of /etc/sudoers file in Linux?
  17. What is a chroot environment in Linux?
  18. Explain the difference between /bin, /sbin, /usr/bin, and /usr/sbin.
  19. How do you configure NFS on a Linux system?
  20. How would you configure an HTTP server (Apache/Nginx) on Linux?
  21. What is a kernel panic? How would you troubleshoot it?
  22. What are cgroups in Linux?
  23. What is the role of auditd in Linux security?
  24. How do you enable core dumps in Linux?
  25. How would you monitor the performance of a Linux system using top, htop, and vmstat?
  26. What is the purpose of strace and how do you use it for troubleshooting?
  27. Explain the difference between IPv4 and IPv6 configurations in Linux.
  28. How do you configure a Linux server as a DNS server?
  29. What is the role of the logrotate utility in Linux?
  30. How would you secure an SSH connection in Linux?
  31. How do you set up an FTP server in Linux?
  32. What are some of the best practices for securing a Linux server?
  33. What is a kernel module, and how do you load and unload them?
  34. How do you apply kernel patches in Linux?
  35. What is the difference between systemctl and service command in Linux?
  36. How do you monitor and manage disk I/O performance in Linux?
  37. What is SELinux in enforcing mode, and how does it impact the system?
  38. How do you manage memory and swap usage in Linux?
  39. How would you configure a web proxy in Linux?
  40. How would you diagnose a system experiencing high CPU usage in Linux?

Linux Admin Interview Questions and Answers

Beginners Question with Answers

1. What is Linux?

Linux is an open-source, Unix-like operating system (OS) that serves as the foundation for a wide range of devices, from servers and desktops to mobile phones and embedded systems. It was originally created by Linus Torvalds in 1991, and its source code is freely available to anyone, making it a key player in the world of open-source software. Unlike proprietary operating systems like Windows or macOS, Linux is built on a philosophy of collaboration, allowing developers to modify and distribute the code.

Linux consists of several components:

  • Kernel: The core part of the system that interacts directly with the hardware, manages system resources, and provides essential services.
  • System Libraries: These are essential for programs to interact with the kernel without directly accessing hardware.
  • System Utilities: Tools and programs that provide user-level services (e.g., text editors, file management utilities, etc.).
  • User Interface: The user can interact with the system either through a graphical user interface (GUI) or the command-line interface (CLI).

Because of its open-source nature, Linux is highly customizable and can be tailored for specific tasks and environments. It is widely used in server environments, cloud computing, embedded systems, and by developers.

2. What are the different types of Linux distributions?

A Linux distribution (distro) is a complete operating system that includes the Linux kernel along with system libraries, utilities, software applications, and a package management system. The distribution determines how the system is configured and which applications come pre-installed. Some popular types of Linux distributions include:

  • Ubuntu: One of the most popular and user-friendly Linux distributions, known for its simplicity and ease of use. It’s based on Debian and widely used in desktops, servers, and cloud environments.
  • Debian: Known for its stability and long release cycles, Debian is the base for several other distributions, including Ubuntu. It is popular for server deployments and is highly valued by users who need a robust system.
  • CentOS: A free, community-driven version of Red Hat Enterprise Linux (RHEL), commonly used in enterprise and server environments. It focuses on stability and long-term support, but its development has shifted to CentOS Stream.
  • Fedora: A cutting-edge distribution sponsored by Red Hat, Fedora is known for incorporating the latest Linux technologies. It is often used by developers and enthusiasts who want to experience the newest features.
  • Arch Linux: A rolling-release distribution aimed at advanced users who prefer to customize every aspect of their system. Arch is known for its simplicity, minimalism, and high degree of control over system components.
  • RHEL (Red Hat Enterprise Linux): A commercial Linux distribution designed for enterprise environments, offering extensive support, certifications, and stability. It’s widely used in businesses and data centers.
  • openSUSE: A community-driven distribution known for its powerful system administration tools, including YaST, and its strong support for both desktop and server use.
  • Linux Mint: Based on Ubuntu, Linux Mint is designed to be a user-friendly desktop distribution. It provides a familiar interface and is suitable for beginners transitioning from Windows.
  • Kali Linux: A distribution specifically designed for security professionals and penetration testers, with a suite of tools for security testing and ethical hacking.

Each distribution has its own package management system, system initialization process, and configuration utilities, which make them unique in terms of use cases and target audiences.

3. What is the Linux kernel?

The Linux kernel is the core of the Linux operating system. It acts as an intermediary between the hardware of the computer and the software (applications and system tools). The kernel is responsible for managing system resources such as the CPU, memory, and storage devices. It also handles input/output (I/O) operations, device management, file systems, network communication, and security.

Key functions of the Linux kernel include:

  • Process Management: The kernel manages processes, allocates CPU time, and ensures efficient multitasking.
  • Memory Management: It handles memory allocation, paging, and virtual memory. It ensures that processes have access to the required memory space while isolating them from each other.
  • Hardware Abstraction: The kernel provides a hardware abstraction layer that allows software to interact with hardware without knowing the specifics of the hardware.
  • Device Drivers: The kernel includes drivers that control hardware components such as network cards, storage devices, and graphics cards.
  • File System Management: The kernel manages file systems, ensuring that data is stored, retrieved, and organized efficiently.

The Linux kernel is modular, meaning that it can load and unload various modules (drivers and system components) as needed.

4. What is a shell in Linux?

A shell in Linux is a command-line interface (CLI) that allows users to interact with the operating system by typing commands. It serves as an intermediary between the user and the kernel, interpreting the commands issued by the user and executing them. The shell processes commands and outputs the result to the terminal.

There are two main types of shells in Linux:

  1. Bash (Bourne Again Shell): The default shell in many Linux distributions, known for its scripting capabilities and extensive features.
  2. C Shell (csh): A shell with C-like syntax, primarily used by users who prefer C-style programming.
  3. Zsh (Z Shell): A highly customizable shell with features like improved tab completion, globbing, and prompt customization.
  4. Fish (Friendly Interactive Shell): A user-friendly shell with a focus on interactive use, it includes features like auto-suggestions and syntax highlighting.

A shell provides an environment where users can run commands, run scripts, navigate the filesystem, and manage processes.

5. What are the different types of shells available in Linux?

There are several types of shells available in Linux, each with its own syntax and features. Some of the most common shells include:

  • Bash (Bourne Again Shell):
    • The most widely used shell, especially in distributions like Ubuntu, CentOS, and Debian.
    • It supports scripting, command history, tab completion, and process control.
  • C Shell (csh):
    • A shell with C-like syntax, designed for users familiar with the C programming language.
    • It introduced features like history and aliases.
  • Zsh (Z Shell):
    • Known for its powerful features, including enhanced tab completion, extended globbing, and better customization options.
    • It’s favored by power users and developers.
  • Fish (Friendly Interactive Shell):
    • A shell designed to be user-friendly with features such as syntax highlighting, autosuggestions, and an easy-to-read interface.
    • It is primarily used by those who prefer an interactive shell experience.
  • Ksh (Korn Shell):
    • A shell developed by David Korn, which is backward compatible with the Bourne Shell and includes additional features such as job control and scripting enhancements.
  • Tcsh:
    • An enhanced version of the C Shell with additional features such as command-line editing, programmable completion, and more.
  • Dash:
    • A lightweight shell that is designed to be POSIX-compliant and is often used as the default system shell in environments where speed is crucial (such as in system scripts).

Each shell has its own strengths, and the choice of shell typically depends on user preferences, scripting requirements, and system environments.

6. How do you list all files in a directory in Linux?

In Linux, you can list all files in a directory using the ls command. This command displays the names of files and directories in the current directory or a specified directory.

Basic Syntax:

ls [options] [directory]

For example, to list the files in the current directory:

ls

To list all files, including hidden files (those starting with a dot):

ls -a

To list files with detailed information such as permissions, ownership, size, and modification date:

ls -l

To list all files, including hidden files, with detailed information:

ls -la

You can also use other options to sort the files by date, size, etc., like:

  • ls -lh (human-readable file sizes)
  • ls -t (sort by modification time)

7. What does the chmod command do?

The chmod (change mode) command in Linux is used to change the file or directory permissions. It controls who can read, write, or execute a file. Linux file permissions are based on three categories: owner, group, and others. The chmod command can modify these permissions using either symbolic or numeric modes.

  • Symbolic Mode:
    • Uses letters to represent user categories and permissions (e.g., r for read, w for write, and x for execute).
    • Example: chmod u+x file.txt adds execute permission to the user (owner).
  • Numeric Mode:
    • Uses numbers to represent permissions. Each permission is assigned a number (read = 4, write = 2, execute = 1), and the sum of these values determines the permissions.
    • Example: chmod 755 file.txt gives the owner full permissions (7 = 4+2+1), and read/execute permissions to group and others (5 = 4+1).

chmod is used for security purposes to restrict or grant access to files and directories.

8. What is the difference between a hard link and a soft link?

In Linux, both hard links and soft (symbolic) links are used to link files, but they behave differently:

  • Hard Link:
    • A hard link is an additional reference (or pointer) to an existing file on the filesystem. Both the original file and the hard link share the same inode and data blocks.
    • Hard links cannot span different file systems, and they cannot be created for directories (except for the . and .. entries).
    • Deleting the original file does not delete the data as long as there are hard links pointing to it.
  • Soft Link (Symbolic Link):
    • A soft link is a special type of file that points to another file or directory by its path.
    • A soft link has a separate inode from the target file and contains a path to the target.
    • If the target file is deleted or moved, the soft link becomes broken (dangling).

Hard links are more direct references to data, while soft links are more flexible and can link across filesystems or link to directories.

9. What are the basic Linux file permissions?

Linux file permissions control who can access files and directories and what actions they can perform on them. The basic permissions are:

  • Read (r): Permission to open and read the file.
  • Write (w): Permission to modify or delete the file.
  • Execute (x): Permission to execute a file (run it as a program).

Permissions are assigned to three categories:

  • User (u): The file's owner.
  • Group (g): The group associated with the file.
  • Others (o): Everyone else.

A typical permission string looks like rwxr-xr--, where the first three characters represent the user's permissions, the next three are for the group, and the last three are for others.

10. What is the ls command used for?

The ls command in Linux is used to list the files and directories in a directory. It is one of the most frequently used commands in Linux, providing an overview of the contents of the specified directory.

  • Basic usage: ls lists files and directories in the current directory.
  • Options:
    • ls -l: Lists files in long format, showing permissions, ownership, size, and modification time.
    • ls -a: Lists all files, including hidden files (those starting with a dot).
    • ls -h: Makes file sizes human-readable (e.g., 1K, 234M).
    • ls -R: Recursively lists all files in subdirectories.
    • ls -t: Sorts files by modification time.

The ls command is essential for navigating and managing files and directories in a Linux environment.

11. How do you check the current working directory in Linux?

To check the current working directory in Linux, you can use the pwd (print working directory) command. This command shows the full path of the directory you are currently in.

Example:

pwd

Output might look like:

/home/user/Documents

This command is essential when navigating the file system to confirm your current location.

12. What is the pwd command used for?

The pwd (print working directory) command in Linux is used to display the full absolute path of the current working directory. It tells you exactly where you are in the file system hierarchy.

Example:

pwd

Output example:

/home/user/Desktop

This command is helpful when you're working in a terminal session and want to verify your directory location.

13. How do you change directories in Linux using the cd command?

The cd (change directory) command in Linux is used to navigate between directories. You provide the path to the directory you want to move to.

Basic Syntax:

cd [directory]

For example:

To go to the /home/user directory:

cd /home/user

To move up one directory level:

cd ..

To go to your home directory:

cd ~

To go to your home directory:

cd ~

To navigate to the previous directory:

cd -

The cd command is essential for navigating the filesystem in a terminal.

14. How do you copy a file in Linux?

To copy a file in Linux, you use the cp (copy) command. This command allows you to create a duplicate of a file or directory at a specified location.

Basic Syntax:

cp [source] [destination]

For example:

To copy a file file.txt from the current directory to the /home/user/ directory:

cp file.txt /home/user/

To copy a directory (and its contents) recursively:

cp -r source_dir destination_dir

To preserve the file's attributes like timestamps and permissions while copying:

cp -p file.txt /home/user/

The cp command is essential for copying files between directories in Linux.

15. How do you move a file in Linux?

The mv (move) command in Linux is used to move or rename files and directories. If the destination directory is different, it moves the file; if the destination is a new name, it renames the file.

Basic Syntax:

mv [source] [destination]

For example:

To move a file file.txt from the current directory to /home/user/:

mv file.txt /home/user/

To rename a file:

mv old_name.txt new_name.txt

To move a directory and its contents:

mv source_dir /home/user/destination_dir

The mv command is versatile for both renaming and moving files and directories in Linux.

16. How do you delete a file in Linux?

To delete a file in Linux, you use the rm (remove) command. This command permanently deletes files, so it should be used with caution.

Basic Syntax:

rm [file]

For example:

To remove a single file:

rm file.txt

To delete multiple files at once:

rm file1.txt file2.txt

To delete a directory and its contents recursively:

rm -r directory_name

To force deletion without confirmation (use carefully):

rm -f file.txt

The rm command is powerful, and files removed with it cannot be easily recovered.

17. What is a process in Linux?

A process in Linux is an instance of a running program. It consists of the program code, its current activity, and the system resources it uses. Each process has a unique process ID (PID) and can be in various states, such as running, sleeping, or stopped.

Processes can be categorized as:

  • Foreground processes: These are processes that interact directly with the user.
  • Background processes: These are processes that run in the background and don't require user interaction.

Every process in Linux is assigned a unique PID, which is used by the system to manage and monitor the process. The Linux kernel uses these PIDs to track and schedule processes for execution.

18. How do you check running processes in Linux?

To check running processes in Linux, you can use the ps (process status) command. The ps command shows information about active processes.

Basic Syntax:

ps

This will display processes running in the current terminal session. To see all processes running on the system, use:

ps aux

Where:

  • a shows processes of all users.
  • u provides user-oriented output (user/owner of the process).
  • x includes processes not attached to a terminal.

To get a dynamic, real-time view of running processes, you can use the top command, which provides a constantly updating list of processes and their resource usage.

19. What is the top command used for?

The top command in Linux is used to display real-time information about the system's processes, resource usage (such as CPU, memory, and disk), and overall system performance. It's an interactive command that provides an overview of active processes.

Basic Syntax:

top

When you run top, it displays:

  • A list of running processes along with their CPU and memory usage.
  • System load averages, uptime, and memory usage.
  • Process IDs (PIDs), users, and the command that initiated each process.

You can press certain keys while in the top interface to interact with it:

  • Press q to quit.
  • Press P to sort by CPU usage.
  • Press M to sort by memory usage.

The top command is especially useful for identifying resource-heavy processes.

20. How do you kill a process in Linux?

To kill a process in Linux, you can use the kill command, which sends a signal to a process to terminate it. By default, it sends a termination signal (SIGTERM) to the process.

Basic Syntax:

kill [PID]

Where PID is the process ID of the process you want to terminate. You can find the PID using commands like ps or top.

For example:

To kill a process with PID 1234:

kill 1234

If the process does not terminate with the default signal, you can use the -9 option to forcefully kill it (SIGKILL):

kill -9 1234

Alternatively, you can use killall to terminate a process by its name, which kills all processes with that name:

killall process_name

Caution: Be careful when using kill and especially kill -9 as it forces processes to stop immediately without cleaning up resources.

21. What is the difference between kill and killall?

Both kill and killall are commands used to terminate processes in Linux, but they operate differently:

  • kill:
    • The kill command is used to send a signal (such as SIGTERM or SIGKILL) to a specific process identified by its Process ID (PID). This command requires you to know the PID of the process you want to kill.

Syntax:

kill [PID]

For example, if you want to kill a process with PID 1234:

kill 1234
  • killall:
    • The killall command is used to terminate all processes that match the specified name. You do not need to know the PID; instead, you provide the name of the process or program.

Syntax:

killall [process_name]

For example, to kill all processes named firefox:

killall firefox

In summary:

  • kill requires the PID of a process.
  • killall terminates processes by name.

22. What is the grep command used for in Linux?

The grep command in Linux is used for searching text within files or output from other commands. It searches for a specified pattern or regular expression and prints lines containing that pattern.

Basic Syntax:

grep [options] pattern [file]

For example:

To search for the word "error" in a file called logfile.txt:

grep "error" logfile.txt

To search for a pattern in the output of another command (e.g., finding processes containing the word apache):

ps aux | grep apache

Common grep options:

  • -i: Ignore case (case-insensitive search).
  • -r or -R: Recursively search through directories.
  • -v: Invert the match, displaying lines that do not match the pattern.
  • -l: Display only the names of files that contain the pattern.

The grep command is extremely useful for searching through large files or outputs for specific information.

23. How do you redirect output to a file in Linux?

In Linux, you can redirect the output of a command to a file using the > (overwrite) or >> (append) operators. This is useful for saving the output of a command to a file instead of displaying it on the terminal.

Overwrite (with >): Redirects output to a file, overwriting any existing content.

echo "Hello, World!" > output.txt
  • This command will create (or overwrite) the file output.txt with the text "Hello, World!".

Append (with >>): Redirects output to a file, appending it to the end of the file.

echo "Hello again!" >> output.txt
  • This will add the text "Hello again!" to the end of output.txt without overwriting its current content.

Redirecting standard error: If you want to capture both standard output (stdout) and standard error (stderr) in the same file:

command > output.txt 2>&1

Redirecting output to files is a fundamental aspect of working with Linux commands and is often used for logging and file manipulation.

24. What is the echo command used for?

The echo command in Linux is used to print text or output to the terminal. It is often used in scripts or command-line operations to display messages or the value of variables.

Basic Syntax:

echo [options] [string]

For example:

To print a simple message:

echo "Hello, World!"

To print the value of a variable:

name="Alice"
echo "Hello, $name"

Common options:

-n: Prevents the trailing newline character.

echo -n "Hello, "
echo "World!"

-e: Enables interpretation of backslash escapes (e.g., \n for a new line).

echo -e "Hello\nWorld!"

The echo command is commonly used in scripts, shell configurations, and for testing purposes.

25. What is the cat command used for in Linux?

The cat (concatenate) command in Linux is used to display the content of files on the terminal, combine multiple files, or create new files by redirecting input.

Basic Syntax:

cat [options] [file(s)]

For example:

To display the contents of a file:

cat file.txt

To concatenate (combine) two files:

cat file1.txt file2.txt

To create a new file by typing input (press Ctrl+D to end the input):

cat > newfile.txt

To number the lines of a file:

cat -n file.txt

The cat command is very useful for viewing and manipulating file content directly from the terminal.

26. What is the purpose of the /etc/passwd file?

The /etc/passwd file in Linux is a text file that contains essential information about user accounts on the system. It defines user details such as the username, password (or placeholder), user ID (UID), group ID (GID), home directory, and default shell.

Each line in /etc/passwd represents one user account, and the fields are separated by colons (:). The general format of each line is:

username:password:UID:GID:GECOS:home_directory:shell

Example:

johndoe:x:1001:1001:John Doe:/home/johndoe:/bin/bash
  • username: The login name of the user.
  • password: A placeholder or an encrypted password (usually stored in /etc/shadow for security reasons).
  • UID: The unique user ID.
  • GID: The primary group ID.
  • GECOS: Full name or a description of the user.
  • home_directory: Path to the user's home directory.
  • shell: The user's default shell.

This file is critical for user management on the system, and only the root user typically has permission to modify it.

27. How do you create a new user in Linux?

To create a new user in Linux, you can use the useradd command followed by the desired username. After creating a user, you can set the user's password using the passwd command.

Basic Syntax:

sudo useradd [username]
sudo passwd [username]

For example:

To create a user named johndoe:

sudo useradd johndoe

To set a password for the new user:

sudo passwd johndoe

You can also specify additional options, such as definin a home directory, shell, or group for the user:

sudo useradd -m -s /bin/bash -G sudo johndoe
  • -m creates the user's home directory if it does not exist.
  • -s /bin/bash sets the default shell to Bash.
  • -G sudo adds the user to the sudo group for administrative privileges.

28. What is the purpose of the /etc/group file?

The /etc/group file in Linux defines the groups to which users belong. This file provides information about user groups, including group names, GIDs, and member usernames. It allows for more efficient management of user permissions, as users in a group can inherit specific access rights for files and directories.

Each line in /etc/group represents one group, with fields separated by colons (:). The general format of each line is:

group_name:password:GID:user_list

Example:

sudo:x:27:johndoe,alice
  • group_name: The name of the group (e.g., sudo).
  • password: A placeholder for group password (rarely used today).
  • GID: The unique group ID.
  • user_list: A comma-separated list of users who are members of the group.

The /etc/group file is used to manage group-based permissions and is typically modified by administrators.

29. How do you check the free disk space in Linux?

To check free disk space in Linux, you can use the df (disk free) command. This command displays information about the available and used disk space on the file system.

Basic Syntax:

df [options]

For example:

To display the disk usage for all mounted file systems:

df

To display disk usage in a human-readable format (with KB, MB, or GB):

df -h

To display disk usage for a specific file system or directory:

df /home

The df command provides a quick way to check overall disk space usage.

30. What is the df command used for?

The df command is used to display the amount of disk space available on the file system, including both used and available space. By default, it shows information about all mounted file systems.

Basic Syntax:

df [options] [file]

For example:

To show disk usage for all mounted file systems:

df

To display disk usage in a human-readable format (with units such as GB or MB)

df -h

The df command is very useful for monitoring disk space and ensuring that the system does not run out of space. You can also specify a particular file or directory to check its disk usage.

31. What is the du command used for in Linux?

The du (disk usage) command in Linux is used to estimate the disk space used by files and directories. It displays the amount of disk space consumed by files and directories, helping you determine how much space is being used on a system.

Basic Syntax:

du [options] [directory]

For example:

To check the disk usage of the current directory:

du

To check the disk usage of a specific directory:

du /path/to/directory

To display the disk usage in a human-readable format (with units like KB, MB, GB):

du -h

To check the total disk usage for a directory and its subdirectories:

du -sh /path/to/directory

The du command is useful for identifying which directories or files are taking up the most disk space.

WeCP Team
Team @WeCP
WeCP is a leading talent assessment platform that helps companies streamline their recruitment and L&D process by evaluating candidates' skills through tailored assessments