Linux Flashcards

1
Q

How can you install software on a Linux system and what are the common package managers used in Linux?

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

What are software packages and package managers?

A

A software package is a collection of files and metadata that contains the information and instructions needed to install, run, and remove a software application or component. Software packages can have different formats, such as .deb, .rpm, .tar.gz, .snap, or .appimage, depending on the distribution and the packaging system used. A package manager is a tool that simplifies the process of installing, updating, and removing software packages by resolving dependencies, checking compatibility, and verifying integrity. Some of the most popular package managers in Linux are apt, yum, dnf, pacman, snap, and flatpak.

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

How to use apt to install and remove .deb packages?

A

Apt is the package manager utilized by Debian-based distributions, such as Ubuntu, Mint, or Kali. It is used to manage .deb packages, which are compressed archives that contain the binary files and the control files of the software. To use apt, you must open a terminal and execute the following commands:

sudo apt update
, which updates the list of available packages from the repositories;

sudo apt install package_name
, which installs a package by name;

sudo apt remove package_name
, which removes a package by name;

sudo apt install /path/to/file.deb
, which installs a package from a local .deb file; and

sudo apt purge package_name
, which removes a package and its configuration files.

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

How to use yum or dnf to install and remove .rpm packages?

A

Yum and dnf are the package managers used by Red Hat-based distributions, such as Fedora, CentOS, or RHEL. These managers work with .rpm packages, which are compressed archives that contain the binary files and the metadata of the software. To use yum or dnf, you need to open a terminal and use certain commands. For example, if you want to update the list of available packages from the repositories, then you should use

sudo yum update
or

sudo dnf update
. If you want to install a package by name, then type in

sudo yum install package_name
or

sudo dnf install package_name
. To remove a package by name, you can use

sudo yum remove package_name
or

sudo dnf remove package_name
. If you want to install a package from a local .rpm file, type in

sudo yum localinstall /path/to/file.rpm
or

sudo dnf localinstall /path/to/file.rpm
. Lastly, if you want to remove a package and its dependencies, use

sudo yum autoremove package_name
or

sudo dnf autoremove package_name

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

Explain the Linux file system / structure

A

The Linux file system structure is hierarchical and follows a standard layout defined by the Filesystem Hierarchy Standard (FHS). Here’s a brief explanation of key directories within the Linux file system:

  1. / (Root Directory):
    • The top-level directory of the Linux file system. All other directories and files branch from here.
  2. /bin (Binary):
    • Contains essential command binaries (executables) that are needed for system booting, repairing, and general system use. Examples include ls, cp, mv, and rm.
  3. /sbin (System Binaries):
    • Contains essential system binaries, typically used for system administration tasks. Examples include fsck, reboot, ifconfig, and iptables.
  4. /etc (Et Cetera):
    • Contains all the system-wide configuration files and shell scripts that are used to boot and initialize system settings. Examples include /etc/passwd for user account information and /etc/fstab for file system mount points.
  5. /dev (Device Files):
    • Contains device files that represent hardware devices. Examples include /dev/sda (a hard disk), /dev/tty (terminals), and /dev/null (a null device).
  6. /proc (Process Information):
    • A virtual file system that contains information about running processes. It provides a mechanism to access kernel information through files. Examples include /proc/cpuinfo for CPU information and /proc/meminfo for memory information.
  7. /var (Variable):
    • Contains variable data files. This includes log files, spool files, and temporary files. Examples include /var/log for log files, /var/spool for printer and mail spools, and /var/tmp for temporary files that need to persist between reboots.
  8. /usr (User):
    • Contains user binaries, libraries, documentation, and source code for second-level programs. Subdirectories include /usr/bin for non-essential user command binaries and /usr/lib for non-essential libraries.
  9. /home (Home Directories):
    • Contains personal directories for users. Each user has a subdirectory within /home named after their username, such as /home/user1.
  10. /lib (Libraries):
    • Contains shared libraries needed by the binaries in /bin and /sbin. These libraries are essential for the system to boot and run the commands in those directories.
  11. /opt (Optional):
    • Contains add-on application software packages. It is typically used for third-party software installations.
  12. /mnt and /media (Mount Points):
    • Used as mount points for temporarily mounting filesystems, such as USB drives, CD-ROMs, and network shares. /mnt is often used for manual mounts, while /media is typically used by the system to automatically mount removable media.
  13. /tmp (Temporary):
    • Used to hold temporary files created by system and user processes. Files in /tmp are typically cleared upon system reboot.
  14. /boot (Boot Loader Files):
    • Contains files needed for the system to boot, including the kernel and initial RAM disk. Examples include the boot loader configuration file and kernel images.
  15. /root (Root Home Directory):
    • The home directory for the root user. It is separate from /home to provide security and organizational benefits.

Understanding this structure is crucial for system administration, troubleshooting, and effective use of a Linux system. Each directory serves a specific purpose, ensuring a well-organized and efficient file system layout.

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

Why the Drive C?

A

Since early computers only had floppy drives, they were called a and b and they were removable, the first hard drive letter turned out to be C.

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

What is Mac’s ancestor?

A

Unix

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

What can you find in /bin and /sbin folder?

A

It is short for binaries and these are the most basic binaries, which is another word for programs or applications. ls, cat etc kind of functions are stored here.
In the sbin folder there are system binaries that a system admin would use and a standard user wouldnt have access without permission. When you install a program on Linux, it’s typically not placed in these folders.

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

What is /boot folder in Linux?

A

It contains everything your OS needs to boot. Bootloaders live here.

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

What is /dev folder in Linux?

A

This is where your devices live. Here you will find your hardware. Everything in Linux is a file, so you can find your disk and your partition in this folder. Everything else also lives here, your webcam, keyboard etc. This is an area where applications and drivers should access.

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

What is /etc folder in Linux?

A

etc has system wide application configuration.

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

What are /lib folders doing?

A

These are where the libraries stored

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

What are /mnt and /media folders for?

A

Floppy disk, external disk, second hard drive, these are here. A B D drive are here. /media OS managed, mnt for us to mount.

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

What is /opt?

A

Optional. For all the applications that we install can go here.

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

What is /proc folder for?

A

This is where all kind of information about system processes reside. Every process has an ID and all the information about a process can be found here. You can also find information about the cpu here.

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

What is /root for?

A

It is the root users home folder. You need root permissions to access here.

17
Q

What is /srv folder?

A

If this is a server like an ftpserver, it would have the files here.

18
Q

What is /sys folder?

A

It is a way to interact with the kernel. This folder is created everytime the system boots up and it is not physically written to the disk, so you wouldnt put files here.

19
Q

What is /usr?

A

Here resides non essential applications for Linex and these are basically user installed applications.

20
Q

What is /home folder?

A

Each user has its own folder inside of home. Personal files and docs. Application variables

21
Q

Tell me about FHS?

A

File Hierarchy Standard. In the early days of Linux, the file system structure was pure chaos so the Linux community rallied around this standard for a consistent directory structure on every distribution.

22
Q

Tell me about key directories in Linux file system

A
  • /bin: The home for executable binaries, such as mount ls cd. bin contains core OS programs that must be accessible before /usr gets mounted at boot.
  • /usr: is a primary home for binaries that are not directly used by OS itself. Most user programs like git or wget live here. It stands for Unix System Resources not user!
  • /usr/local/bin : holds executables installed by the admin, usually after buiilding them from source.
  • sbin: sbin house sysadmin utilities that require root access like iptables and sshd.

When a binary exists in /bin /usr/local/bin or /usr/bin you can specify the default by reordering the directory precedence in the path variable.

  • /lib : contains shared library files essential for /bin and /sbin binaries to function properly. These libraries need to be accessible early in the boot process before mounting /usr. C library routines and compiler runtimes…
  • /usr/lib: User libraries that are not critical early in the boot process.
  • /etc: Home of Linux configuration files. Text based config files control everything from networking to authentication services. ssh_config for example or fstab.
  • /home: stores documents, media and projets.
  • /root: Exclusive to administrators.
  • /var: Fast changing data like logs and caches live under /var
  • /var/log: We care about this folder to inspect about hardware events, security issues or performance problems.
  • /run: Contains volatile run-time info like systemd details, user sessions and logging daemons. System services use run for ongoing communication via sockets and lock files. For example, mysql.sock might be crucial for db access.
  • /proc: OS state via cpuinfo, view filesystem mounts, and dive deeper with tools like lsof, strace and pmap.
  • /sys: exposes lower-level kernel and hardware objects, allowing granular monitoring, configuration of components live devices, modules, network stack via virtual files. (Socket layer, TCP stack, netfilter, traffic control, network interface) Sys and proc combined they provide complete system observability spanning high level metrics to low level component interactions. These inspection points are useful for performance tuning and forensic triage.
23
Q

What is Linux and what makes it different from other operating systems?

A

Linux is a free, open-source operating system based on Unix. It was released by Linus Torvalds in 1991.
What makes it different:
- Open Source Nature
- Flexibility and Customization: Linux offers extensive flexibility and customization options. It can be installed on a wide range of computer hardware devices, from mobile phones, tablets, and routers, to game consoles, desktops, mainframes, and supercomputers.
- Security: Linux is generally considered to be more secure than many other operating systems. Its permission and user role features require that user and administrator accounts have separate permissions.
- Stability and Reliability: Linux is known for its stability and reliability. It is often used in server environments because Linux-based servers don’t need to be rebooted periodically to maintain performance levels.
- Community Support: Being open-source, Linux has a large community support system with numerous forums, communities, and distributions to help users.
- Cost: Linux can be a more cost-effective option for both personal and enterprise users as it is mostly free to use. Unlike other major operating systems, which can require costly licenses, most Linux distributions are available to download, use, and distribute at no cost.
- Package Management: Linux distributions come with their own package management systems. These tools allow users to easily install, update, and remove software.
- Performance: Linux systems generally run faster and with greater performance consistency than many other operating systems. They are highly effective in handling numerous processes at once, and generally manage system resources very efficiently.
- Privacy: Linux tends to collect much less data about user activities compared to some other operating systems.
- Variety of Distros: Linux offers a variety of distributions tailored for different types of users and systems. From lightweight distros like Lubuntu and Arch Linux for older hardware to those designed for specific professional use cases like CentOS for servers, there is a Linux for almost every purpose.

24
Q

What’s the command for changing the permission of a file? Give an example

A

chmod
This command allows you to set the read, write, and execute permissions for the owner, group, and others who interact with a file or directory.

Permissions in Linux are defined for three types of users:
Owner
Group
Others

Permissions are represented numerically or symbolically:
Read (r) = 4
Write (w) = 2
Execute (x) = 1

Example 1: Using Numeric (Octal) Notation
If you want to set the owner permissions to read and write, group permissions to read, and no permissions for others, you would calculate the permissions as:

Owner: Read + Write = 4 + 2 = 6
Group: Read = 4
Others: No permissions = 0
chmod 640 [filename]

Example 2: Using Symbolic Notation
To add execute permission to a file for the owner, you can use symbolic notation like this:
chmod u+x [filename]

25
Q

Can you breakdown this command?
chmod u+x [filename]

A

Breaking Down chmod u+x [filename]
chmod: This is the command used to change the permissions of a file or directory.

u+x:

u: Stands for “user,” but in this context, it specifically refers to the file or directory’s owner. The owner is typically the creator of the file or directory, unless ownership has been changed.
+: This indicates that you’re adding a permission.
x: Stands for “execute,” which allows the file to be run as a program or the directory to be entered and executed in.
[filename]: This should be replaced with the actual name of the file or directory you want to modify.

What Does u+x Do?
When you run chmod u+x [filename], you’re instructing the system to add execute (x) permissions to the user/owner (u) of the file specified by [filename]. Here’s what happens:

If [filename] is a regular file, adding execute permissions means that the user who owns the file can now run it as a program. This is common for script files or compiled programs that need to be executed directly from the command line.
If [filename] is a directory, adding execute permissions allows the owner to enter (cd into) the directory and access files and subdirectories within it. Note that for directories, execute permission is necessary to access the contents of the directory.

Practical Example
Suppose you have a script file named script.sh that you’ve just created or downloaded. By default, it might not have execute permissions, which means you can’t run it directly from the shell. To enable execution, you would use:
chmod u+x script.sh
After this command, as the owner, you can run the script by typing ./script.sh in the terminal.

Security Considerations
Adding execute permissions should be done cautiously. Executable files can perform any operations that the user has permission to perform. Hence, you should only add execute permissions to files that you trust and that require execution for their intended function.

In summary, chmod u+x [filename] is a way to ensure that the owner of the file has the necessary permissions to execute it, enhancing functionality while maintaining control over who can execute the file.

26
Q

What’s the command for changing the ownership of a file? Give an example

A

chown
This command allows you to change the owner and/or the group owner of a file or directory.
chown [owner][:[group]] [file]
Parameters:
[owner]: Specifies the new owner’s user ID or name.
[group]: Optionally, specifies the new group ID or name. If only a colon is used with no group name, the group of the file is changed to the login group of the new owner.
[file]: The file or directory whose ownership you want to change.

Example 1: Changing the Owner
To change the owner of a file named example.txt to a user named john:

chown john example.txt

Example 2: Changing the Owner and Group
To change both the owner and the group of a file named example.txt to john and admin respectively:
chown john:admin example.txt

Example 3: Changing the Group Only
If you want to change only the group of a file and leave the owner unchanged, you can use:
chown :admin example.txt

Recursive Change
If you need to change the ownership of a directory and all of its contents (files and subdirectories), you can use the -R (recursive) option:
chown -R john:admin /path/to/directory
This recursively changes the owner and group of all files and subdirectories within /path/to/directory to john and admin.

27
Q

What’s a command for killing a process given its PID? Give an example

A

kill
Steps to Kill a Process:
Find the PID: Before you can kill a process, you need to know its PID. You can find the PID by using commands like ps, top, or pgrep. For example:
ps aux | grep process_name

Use the kill Command: Once you have the PID, you can use the kill command to terminate the process.
kill 1234

Specifying a Signal:
You can also specify a different signal with the kill command if needed. For example, if the process does not terminate with the default TERM signal, you might need to send the KILL signal, which forcefully terminates the process and cannot be ignored:
kill -9 1234
Here, -9 represents the KILL signal, which forcefully stops the process.

Common Signals:
SIGTERM (-15): Gracefully terminates the process. The process can clean up before it terminates.
SIGKILL (-9): Forcefully terminates the process. The process cannot ignore this signal and does not perform any cleanup.

If you prefer to terminate processes by name instead of PID, you can use killall or pkill:
killall firefox
pkill -f firefox

28
Q

What’s a command to list all the processes running? Give an example

A

ps

To list all the processes running on a Linux system, the ps command is commonly used. This command displays information about active processes. By itself, ps shows only the processes associated with the terminal session you are using, but it can be combined with various options to extend or change the display.

Commonly Used ps Options:
ps aux: This is a widely used option combination to list all the running processes on the system, including those started by other users.
a: Show processes for all users
u: Display the user/owner of the process
x: Include processes without a controlling terminal

ps aux

This command will output several columns of information, such as:
USER: The username of the process owner.
PID: Process ID.
%CPU: CPU usage of the process.
%MEM: Memory usage of the process.
VSZ: Virtual memory size of the process.
RSS: Resident set size, the non-swapped physical memory the process is using.
TTY: Terminal type associated with the process.
STAT: Process state.
START: Starting time or date of the process.
TIME: Total CPU time used.
COMMAND: Command with all its arguments as a string.

ps aux -o pid,user,comm
top

29
Q

What’s the command, named after a protocol, to connect to a remote server in Linux? Give an example

A

ssh

ssh john@192.168.1.100

With -p option
ssh -p 2222 john@192.168.1.100

To avoid typing a password each time you connect, you can use SSH keys. First, generate a key pair on your client machine (if you haven’t already) using:
ssh-keygen

Then, copy your public key to the remote server using:
ssh-copy-id john@192.168.1.100
After this, you can connect to the server without a password, as long as your private key is accessible and not protected by its own passphrase (or you have the passphrase saved in a key manager).

Running a command remotely:
ssh john@192.168.1.100 “ls -l /home/john”

30
Q

What’s a service in Linux?

A

In Linux, a service (often referred to as a daemon) is a background process that is designed to run independently of user sessions. Services often start at system boot (or when manually started) and run continuously until the system shuts down. They do not have a direct interface with the user, but they work in the background to handle system tasks, user requests, network communications, or other processes.

Characteristics of Linux Services:
Background Execution: Services run in the background and do not require user interaction.
Long-running: These processes are typically initiated at system startup and continue running until the system is shut down.
System or Application Tasks: Services can perform a variety of tasks, from system-related jobs like logging, system monitoring, and managing network connections, to application-specific tasks such as web serving, database management, or file sharing.
Managed by Init Systems: Services are usually managed by an initialization system. The traditional system used was SysVinit. However, most modern Linux distributions have adopted systemd as their init system, which provides more features and a unified standard for managing services.

systemd is the most common init system and service manager on current Linux distributions. It uses units to manage different resources. The type of unit used for services is called a “service unit”.

Basic Commands to Manage Services with systemd:
Start a service: sudo systemctl start [service-name]
Stop a service: sudo systemctl stop [service-name]
Enable the service to start at boot: sudo systemctl enable [service-name]
Check the status: sudo systemctl status [service-name]
sudo systemctl restart [service-name]

31
Q

What does it happen when you launch $? in bash?

A

When you launch or print $?, Bash outputs the exit status of the most recently completed command.

32
Q

What is the difference between a process and a thread?

A

When the code in the file is loaded in the memory and executed by the processor, it becomes a process. A thread is a unit of execution within a process. A process has at least one thread. It is called the main thread.

33
Q

What is an application?

A

It is an executable file. It contains the code or a set of processor instructions, that is stored as a file on disk. When the code in the file is loaded in the memory and executed by the processor, it becomes a process.

34
Q

What is a process?

A

When the code in the file is loaded in the memory and executed by the processor, it becomes a process. An active process also includes the resources the program needs to run. They are managed by the operating system. Some examples of these resources are
- processor registers
- program counters
- stack pointers
- memory pages assigned to the process for its heap and stack
Each process has its own address space and they can not corrupt each others address space.
Chrome tabs example

35
Q

What is a thread?

A

A thread is a unit of execution within a process. A process has at least one thread. It is called the main thread. A process may have many threads. Threads within a process share a memory address space and they can corrupt each other when they malfunction. And threads can communicate with each other using the shared memory space. One misbehaving thread can take down the entire process.

36
Q

How does the OS run a thread or process on a CPU?

A

Scheduler - context switching. This is expensive.
https://www.youtube.com/watch?v=4rLW7zg21gI&ab_channel=ByteByteGo

37
Q
A