Skip to content
NovaDen
Go back

Linux Foundations

Introduction

Linux is an operating system, the same way Windows and macOS are. The difference is what’s underneath: it’s built around the Linux kernel, and most of the surrounding ecosystem is open source. In practice, that’s what you’ll find running most servers, containers, embedded devices, and the security tools you’ll be working with.

Core Components

A Linux system is made up of a few layered pieces:

Distributions

A distribution (or “distro”) is an operating system built on top of the Linux kernel, packaged with its own selection of utilities, package manager, default shell, and desktop environment. A few common ones:

The kernel underneath is the same. What differs is the packaging, defaults, and philosophy.

Filesystem Hierarchy

Linux organizes everything (files, devices, even processes) into a single tree rooted at /. Knowing what each top-level directory is for makes the system far easier to navigate.

PathDescription
/The root directory. Everything hangs off it.
/binEssential command binaries available to all users.
/bootBootloader files and kernel images.
/devDevice files representing hardware.
/etcSystem-wide configuration files.
/homeUser home directories.
/libShared libraries needed by /bin and /sbin.
/mediaMount points for removable media.
/mntTemporary mount point for manual mounts.
/optOptional or third-party software.
/rootHome directory for the root user.
/sbinSystem administration binaries, mostly for root.
/tmpTemporary files. Usually wiped on reboot.
/usrUser programs, libraries, and documentation.
/varVariable data: logs, mail spools, caches.

The Shell

The shell is a text-based interface that lets you communicate directly with the operating system. The most common one is the Bourne-Again Shell (BASH).

When you open a terminal, you’ll see a prompt that looks something like this:

kayra@fedora:~/SoulSiphon/PersonalWork/novaden-blog$

Breaking that down:

When you’re logged in as root, the prompt symbol changes to #:

root@fedora:/home/kayra/SoulSiphon/PersonalWork/novaden-blog#

That single character is a useful safety cue. If you see #, you have full administrative privileges and can do real damage.

Relative vs Absolute Paths

There are two ways to reference a file or directory:

For example, cd /opt/ will always land you in /opt regardless of where you are, because it’s an absolute path. By contrast, cd opt only works if you’re already sitting in /, since it’s interpreted relative to wherever you are.

Two special symbols come up constantly in relative paths:

File Descriptors and Redirection

A file descriptor (FD) is a reference, maintained by the kernel, that lets the system manage input/output operations. Every process starts with three file descriptors by default:

FDNamePurpose
0STDINStandard input. Data fed into a command.
1STDOUTStandard output. Regular output from a command.
2STDERRStandard error. Error messages.

Because these are just numbered streams, you can redirect them independently. The shell uses < for input and > for output:

# Discard error messages
command 2>/dev/null

# Send stdout and stderr to separate files
command 1>stdout.txt 2>stderr.txt

# Feed a file in as stdin
cat < input.txt

Note: When you use > to redirect output, the target file is created if it doesn’t exist and overwritten without warning if it does. Use >> to append instead.

You can also chain commands together by piping STDOUT from one into STDIN of the next using |. This is how you stitch small Linux commands together into bigger workflows:

find /etc/ -name "*.conf" 2>/dev/null | grep systemd | wc -l

That one-liner finds every .conf file under /etc/, silently discards permission errors, filters for ones mentioning systemd, and counts the results.

Exit Codes

When a command finishes, it returns a numeric exit code (also called exit status). 0 means success, and anything else means something went wrong. The convention is universal: shells, scripts, CI runners, and other programs all branch on it.

You can inspect the most recent command’s exit code with the special variable $?:

ls /nonexistent
echo $?     # 2

A few codes show up often enough to be worth recognizing:

CodeMeaning
0Success
1General error (catch-all)
2Misuse of the command (bad arguments, syntax)
126Found but not executable (e.g. missing x bit)
127Command not found
128+NKilled by signal N (so 137 = SIGKILL/9, 130 = SIGINT/2 from Ctrl+C)

Two operators chain commands based on the previous exit code:

# Only run the binary if the build succeeded
make && ./run

# Print a fallback message if the request failed
curl -fsSL example.com || echo "request failed"

In shell scripts, you set your own exit code with exit N. exit 0 declares success, and any nonzero value signals failure to whatever called the script. This is what makes set -e, CI pipelines, and pre-commit hooks work: they’re all just reading $?.

Permissions

Linux permissions are assigned to users and groups. A user can belong to multiple groups, and permissions stack across them.

Every file or directory has:

Representing Permissions

Permissions can be written in two equivalent ways: as letters (rwx) or as numbers. Each permission has a numeric value:

You sum the values to get a single digit per category. A three-digit number (e.g. 744) gives owner, group, others, in that order.

For example, a file with read/write/execute for the owner and read-only for everyone else:

That gives 744.

What Each Permission Actually Means

The r, w, x bits mean different things for files and directories, which is a common source of confusion:

PermissionOn a fileOn a directory
Read (r)View the file’s contentsList the directory’s contents (names of files and subdirectories)
Write (w)Modify the file’s contentsCreate, delete, or rename entries inside the directory
Execute (x)Run the file as a programTraverse the directory (e.g. cd into it, run ls -l inside it)

Gotcha: Read on a directory lets you list names, but without execute you can’t actually access anything inside it.

Special Permissions

Beyond the standard rwx bits, three special permission bits show up regularly, especially in security contexts:

Quick reference: the actual commands for changing ownership, permissions, redirection, and everyday shell tasks live in the Linux Cheat Sheet.


Share this post on:

Previous Post
Penetration Testing Fundamentals