linux interview questions Flashcards

1
Q

If you don’t know the options to a command, where do you go to look them up?

A

You can use man pages with man <command></command>
use -help
info command
Documentation in /usr/share/doc:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is swap and when is it used?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where would someone look to find system logs?

A

/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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can I see all processes that are running? How about which ones are taking up the most CPU/Memory?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you restart a service?

A

sudo systemctl restart <service-name></service-name>

  • to check status: sudo systemctl status <service-name></service-name>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you see what IP address is assigned to the box?

A

ip Command: This is the most common method on modern Linux systems.
- ip addr show
on older system: ifconfig

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you install a package for both RHEL and Ubuntu/Debian?

A

For RHEL use yum install command
for ubuntu/debian use apt update/install

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is /etc/fstab used for?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you format a partition/drive?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is /root used for?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a user’s $PATH?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What various commands are used to extract files from an archive?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an inode, and what is it used for? What can you do with an inode?

A

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:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What commands would be used to add a new drive to a volume group and extend a logical volume?

A
  • 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:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is /proc used for? How about /sys?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you display which kernel modules are loaded? How do you load a module? Where do you configure it so a module loads on boot? How do you unload a module?

A

how to. display: lsmod
modinfo <module_name>
cat /proc/modules</module_name>

how to load: To load a kernel module, you use the modprobe or insmod command:

load on boot: To configure a kernel module to load automatically at boot, you can add it to the appropriate configuration file: Add the module name to the /etc/modules file:

to unload: To unload a kernel module, you can use the modprobe or rmmod command:

17
Q

What is “load average”? What intervals is load average shown as? How do you show the load average?

A

Load average is a system performance metric that represents the average number of processes that are either in a runnable state (actively using CPU) or waiting for CPU time over a specific period. It helps gauge how busy the system is

Load average is typically displayed for three time intervals:

1 minute: The average load over the last minute.
5 minutes: The average load over the last five minutes.
15 minutes: The average load over the last fifteen minutes.

You can view the load average in several ways:

Using the uptime Command:
18
Q

How do you show which ports are being listened on?

A

The netstat command can display network connections, routing tables, interface statistics, and more. To see only listening ports, use: netstat -tuln

The ss (socket statistics) command is a modern replacement for netstat. To list listening ports, you can use:

19
Q
A