1. What is Linux, and what are its key features?
Linux is an open-source, Unix-like operating system. Key features include:
- Multitasking: Running multiple processes simultaneously.
- Multi-user capabilities: Multiple users can work on a system at the same time.
- Security: Strong security features like user permissions, SELinux, and firewalls.
- Portability: Can run on many hardware platforms.
- Open-source: The source code is available to everyone.
2. What are the different types of file systems supported by Linux?
Linux supports a variety of file systems, including:
- ext4: The most commonly used Linux file system.
- XFS: High-performance file system used in enterprise environments.
- Btrfs: A newer file system with advanced features like snapshots and volume management.
- NTFS: Windows file system, supported for read/write by Linux using third-party drivers.
- FAT32: Common for external storage devices.
- ReiserFS, JFS: Less commonly used but still supported.
3. Explain the concept of process management in Linux.
Linux uses a process-based model where each task is considered a process. Key concepts include:
- Process States: Running, Sleeping, Stopped, Zombie.
- PID (Process ID): Each process is assigned a unique identifier.
- Forking and Executing: Processes are created using
fork()
and executed usingexec()
. - Process Scheduling: The Linux kernel uses algorithms to decide which process gets CPU time.
- Tools like
ps
,top
,htop
, andkill
are used to manage processes.
4. What is the difference between a hard link and a symbolic link?
- Hard link: Points directly to the data on the disk. It cannot link to directories and cannot span across different file systems.
- Symbolic link: Also known as a soft link, it is a file that points to another file or directory by path. It can span across file systems and can link to directories.
5. How would you check disk space usage in Linux?
You can use the following commands to check disk usage:
df
: Displays the disk space usage of mounted file systems.du
: Displays disk usage for files and directories. Example:du -sh /home/user
gives a human-readable summary of the disk usage of a directory.
6. What is the purpose of the chmod
command?
chmod
is used to change the permissions of a file or directory in Linux. It uses symbolic (rwx) or numeric (octal) notation to specify who can read, write, or execute a file. Example:
chmod 755 file
: Sets the permissions so the owner can read/write/execute, and others can read/execute.
7. What are runlevels in Linux?
Runlevels represent different system states. The most common runlevels are:
- Runlevel 0: Halt (shutdown).
- Runlevel 1: Single-user mode.
- Runlevel 3: Multi-user mode with networking (CLI).
- Runlevel 5: Multi-user mode with GUI.
- Runlevel 6: Reboot.
You can view or change the current runlevel with runlevel
or init
.
8. What is the difference between apt-get
and yum
?
apt-get
: A package manager for Debian-based systems like Ubuntu. It uses.deb
packages.yum
: A package manager for Red Hat-based systems like CentOS. It uses.rpm
packages.
Both are used for installing, updating, and removing software packages.
9. What is the grep
command used for?
grep
is used to search for specific patterns or text within files. Example:
grep 'pattern' file.txt
: Searches for the word “pattern” infile.txt
.grep -r 'pattern' /dir
: Recursively searches for the pattern in all files within the directory.
10. What are cron jobs in Linux?
Cron is a time-based job scheduler in Linux. Cron jobs allow you to schedule scripts or commands to run at specific times or intervals. They are defined in the crontab file. Example of a cron job:
* * * * * /path/to/script.sh
: Runs the script every minute.
To edit the cron table, you can use crontab -e
.
11. How do you monitor memory usage in Linux?
To monitor memory usage, you can use tools like:
free
: Displays free and used memory.top
orhtop
: Shows real-time memory usage of processes.vmstat
: Provides detailed system performance information, including memory, processes, and swap usage.
12. Explain how the ps
command works.
The ps
command displays information about the running processes. Some useful options include:
ps aux
: Shows a detailed list of all processes running on the system.ps -ef
: Provides a standard format for displaying all processes.
13. What is the sudo
command and how does it work?
sudo
stands for “superuser do” and allows a permitted user to execute a command as the superuser or another user. This is typically used for administrative tasks that require elevated privileges. Example:
sudo apt-get update
: Runs theapt-get update
command with root privileges.
14. How do you check if a service is running in Linux?
You can check if a service is running using commands like:
systemctl status service-name
: Checks the status of a service on systems usingsystemd
.service service-name status
: Used on older systems that useinit.d
.
15. What is the difference between kill
and killall
?
kill
: Sends a signal to a specific process by its PID (Process ID).killall
: Sends a signal to all processes by their name. For example,killall nginx
kills all processes namednginx
.
16. How do you view and configure network settings in Linux?
You can view network settings using:
ifconfig
(older systems) orip addr
(newer systems) to view network interfaces and IP configurations.netstat -tuln
: Displays listening ports. To configure network settings, you would edit files like/etc/network/interfaces
(Debian-based) or/etc/sysconfig/network-scripts/ifcfg-eth0
(Red Hat-based).
17. What is SELinux, and what are its modes?
SELinux (Security-Enhanced Linux) is a security feature that provides a mechanism for enforcing security policies on the system. It has three modes:
- Enforcing: SELinux policies are enforced.
- Permissive: SELinux logs actions but does not enforce policies.
- Disabled: SELinux is turned off.
You can check the SELinux mode with sestatus
and modify it via /etc/selinux/config
.
18. What is a symbolic link, and how do you create it?
A symbolic link (symlink) is a pointer to another file or directory. To create a symlink, use the ln -s
command:
ln -s /path/to/original /path/to/link
: Creates a symbolic link.
19. What is the Linux kernel, and what is its role?
The Linux kernel is the core part of the operating system, responsible for managing hardware, system resources, and communication between software and hardware. It controls everything from process management to memory allocation.
20. How do you create a new user in Linux?
You can create a new user with the useradd
command:
sudo useradd -m username
: Creates a new user with a home directory.sudo passwd username
: Sets a password for the user.
21. What is the tar
command used for?
The tar
command is used to create and extract compressed archive files. Example:
tar -czf archive.tar.gz /path/to/directory
: Creates a compressed.tar.gz
archive.tar -xzf archive.tar.gz
: Extracts a.tar.gz
archive.
22. How do you update and upgrade packages in Linux?
- On Debian-based systems (Ubuntu): Use
sudo apt update
to update the package list andsudo apt upgrade
to upgrade installed packages. - On Red Hat-based systems (CentOS): Use
sudo yum update
.
23. What are the different types of users in Linux?
- Root: The superuser with full administrative privileges.
- Regular users: Users who have limited permissions, usually defined by groups.
- Service accounts: Accounts used by services to run processes.
24. How do you manage disk partitions in Linux?
To manage disk partitions, you can use tools like:
fdisk
: For managing MBR partitions.parted
: For managing GPT partitions.lsblk
: To list block devices.
25. What is the df
command, and what does it do?
The df
command displays disk space usage for mounted file systems. Example:
df -h
: Shows the disk space usage in human-readable format (e.g., MB or GB).