linux interview questions Flashcards
If you don’t know the options to a command, where do you go to look them up?
You can use man pages with man <command></command>
use -help
info command
Documentation in /usr/share/doc:
What is swap and when is it used?
Swap is a dedicated space on stoarge device that acts as virtual memory when the physical ram is being fully utilized.
-inactive data in RAM is moved to swap space, freeing up RAM for active processes.
Where would someone look to find system logs?
/var/log/syslog or /var/log/messages
- General system logs that include messages from the kernel and various system services
- /var/log/auth.log: Logs all authentication-related event
-/var/log/kern.log: Contains kernel logs, including hardware errors and kernel events
-/var/log/dmesg: Records boot-time messages
-/var/log/boot.log: Contains messages related to the boot process
-/var/log/apache2/ (or /var/log/httpd/): Directory for Apache web server logs
How can I see all processes that are running? How about which ones are taking up the most CPU/Memory?
- ps aux shows all running processes with details like the user, process ID (PID), CPU/memory usage, etc.
- top in the terminal provides a real-time view of running processes, sorted by CPU usage by default.
- If available, htop is an enhanced version of top, offering an interactive, color-coded view of processes. You can scroll and sort by CPU, memory, or other criteria.
How do you restart a service?
sudo systemctl restart <service-name></service-name>
- to check status: sudo systemctl status <service-name></service-name>
How do you see what IP address is assigned to the box?
ip Command: This is the most common method on modern Linux systems.
- ip addr show
on older system: ifconfig
How do you install a package for both RHEL and Ubuntu/Debian?
For RHEL use yum install command
for ubuntu/debian use apt update/install
What is /etc/fstab used for?
The /etc/fstab file in Linux is a configuration file that defines how and where storage devices, filesystems, and partitions are automatically mounted on the system at boot time
How do you format a partition/drive?
1 - Identify the Partition/Drive: Use lsblk or fdisk -l to list all drives and partitions
2 - Unmount the Partition sudo umount /dev/sdX1
3 - Format the Partition:example ext4 sudo mkfs.ext4 /dev/sdX1
4 - Verify the Format: Use lsblk
5 - Mount the Partition sudo mkdir -p /mnt/mydrive
sudo mount /dev/sdX1 /mnt/mydrive
What is /root used for?
In Linux, the /root directory is the home directory for the root user, which is the superuser or administrator with full access to all system files and commands.
What is a user’s $PATH?
A user’s $PATH is an environment variable in Linux and Unix systems that specifies a list of directories the shell searches when you type a command
What various commands are used to extract files from an archive?
- To extract files from a .tar archive:
tar -xf archive.tar - tar.gz or .tgz (.tar.gz, .tgz)
To extract files from a gzipped tarball
tar -xzf archive.tar.gz - unzip archive.zip
- gunzip file.gz
- unrar x archive.rar
What is an inode, and what is it used for? What can you do with an inode?
An inode (index node) is a fundamental data structure
What Is It Used For?: Inodes allow the file system to manage files efficiently, providing quick access to file metadata without needing to read the entire file. By maintaining metadata separately, the file system can keep track of files and directories even if their names change.
what can you do?
- Access File Metadata:
- Check Inode Usage: Use df -i to check the inode usage of a file system, which helps determine how many inodes are free or used.
- Hard Links: You can create hard links to a file. Multiple filenames can point to the same inode, allowing the same data to be accessible by different names.
- Inode Recovery: Tools like fsck (file system check) can be used to repair file systems, checking and fixing issues with inodes.
- View Inode Details: You can use the stat command to display detailed information about a file, including its inode number:
What commands would be used to add a new drive to a volume group and extend a logical volume?
- Use the pvcreate command to create a physical volume on the new drive
- Use the vgextend command to add the new physical volume to an existing volume group.
- To extend the logical volume, use the lvextend command. You can specify the amount of space to add (e.g., +10G for 10 GB) or use all available space in the volume group (-l +100%FREE):
- After extending the logical volume, you need to resize the filesystem to use the newly allocated space. The command you use depends on the filesystem type:
What is /proc used for? How about /sys?
- The /proc directory is a virtual filesystem that contains a wealth of information about system processes and kernel parameters. It provides a way for users and applications to interact with the kernel.
- The /sys directory is part of the sysfs virtual filesystem, which exposes information and configuration options about devices, kernel modules, and system hardware. It is designed for kernel interaction and device management.