A couple of engineers who initially working on an operating system called Multics. Multics was to be a time-sharing operating system. However, it started falling apart and these two engineers from AT&T branched off to make their own, smaller version of this. This turned out to be UNIX, which sarcastically meant the "uniplexed" version of Multics.
AT&T was trying to standardize their System V version of UNIX. But then, UC Berkeley made their own version of an OS based off of UNIX which they called BSD. BSD shipped with networking capabilities. This period of competition among companies to standardize their OS is termed the UNIX wars. And also AT&T copyright striked BSD.
To avoid legal issues, Stallman made an operating system based on UNIX by remaking its code. So, GNU doesn't contain any code from UNIX. It even stands for "GNU is Not UNIX".
GNU had its own kernel called GNU Hurd, but it was incomplete. Around the same time, Linus Torvalds was working on his hobby project, the Linux kernel. This kernel was then integrated with GNU to give us GNU/Linux.
What we commonly refer to everyday as Linux is actually GNU/Linux. GNU/Linux was free, both free as in cost and free as in freedom.
There was no organization making decisions. The Linux kernel is free, and anyone can make their own distro. So, distros started popping up, just because people could make them. Softlanding, Yggdrasil were among the earliest distributions. Slackware was based off of Softlanding and openSUSE is based off of Slackware.
NetworkManager is a service that continuously scans for networks, and connects to the most preferred ones. Wired networks are given more preference over wireless networks. This program is used a lot on laptops where wireless network management is a necessity and we keep switching between networks. For servers, this is completely unnecessary.
NetworkManager has been widely adopted by lots of distributions to run by default, such as Debian and Ubuntu. But on enterprise distributions like CentOS and Red Hat, NetworkManager is not configured or installed by default.
The oldest and most widely accepted way of doing this is through the /etc/hosts
file. This file contains information (in a line by line) about IP addresses and their names in the following format:
127.0.0.1 localhost
127.0.1.1 zephyrus-ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
This file however, contains only local mappings and is best reserved for mappings that are required during boot. Other mappings can be found using DNS or LDAP.
On Linux, the configuration file for the DHCP client can be found at /etc/dhcp/dhclient.conf
.
A network interface is just hardware that can connect to a network. Machines with multiple ethernet ports, for example, will have different network interfaces controlling each port. Every network interface (hardware, not virtual) has a unique MAC address (also called hardware address) (which is chosen at time of manufacture) to identify itself.
Every machine has the lo
network interface, which is virtual and is a loopback. A loopback interface is used by a machine to connect to itself. The other interfaces are hardware dependent. On my laptop for example:
wahid@zephyrus-ubuntu:~$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
link/ether 50:eb:f6:e1:84:26 brd ff:ff:ff:ff:ff:ff
altname enp2s0
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
link/ether b4:8c:9d:5b:1d:6b brd ff:ff:ff:ff:ff:ff
There is the before mentioned lo
interface. Then there is a eno1
interface that controls the ethernet port and a wlp3s0
wireless network interface.
These network interfaces can be turned on and off using
ip link set <device> <on|off>
When a network packet bound for some other host arrives, then the packet's destination IP is searched for in the kernel's routing table. From here, one of two things can happen:
(To understand how the packet is sent from a device to the router via Ethernet : ARP)
0.0.0.0
) is invoked.Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 wlp3s0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp3s0
ip -s link
command gives us network statistics for each network interface on a device.
Secure SHell (ssh) is a protocol for remote logins. It is a client-server protocol that requires that the remote machine be running an SSH daemon. OpenSSH, an open source implementation of SSH is the standard on almost all versions of UNIX and GNU/Linux.
Basic usage: ssh user@host
or ssh -l user host
When we use ssh to connect to a remote host, that is not recognized by our machine (a remote host that we have previously not connected to), the server sends a hash of its public key called the key fingerprint. If we choose to accept this "unknown" remote server's fingerprint, then the fingerprint is added to ~/.ssh/known_hosts
.
These are stored at ~/.ssh
. However, if this directory doesn't have the permissions set to 0700
, it is ignored. The SSH protocol can make use of public key cryptography (it also has other means of authentication) for authentication.
Here is how SSH is usually configured an used:
ssh-keygen
ssh-keygen
can be used to generate specific types of keys with the -t
flag.ssh-keygen -t rsa -b 4096
generates an RSA key with 4096 bits.~/.ssh/id_rsa
and ~/.ssh/id_rsa.pub
respectively.~/.ssh/authorized_keys
, then we are allowed to login to this account via SSH.
It is necessary that our remote user's ~/.ssh
directory have the permssions set as 0700
and that ~/.ssh/authorized_keys
(which contains our public key) have the permissions set to 0600
.
ssh-agent
is a daemon, that caches private keys. When using ssh
, the private keys that are cached are used automatically. It is also possible to have multiple private keys cached.
ssh-add
command as follows - ssh-add ~/.ssh/id_rsa
ssh-add -l
ssh-add -d ~/.ssh/id_rsa
(This one is weird, it apparently requires that the public key be present in the same directory as the key we are trying to remove. If we don't have the public key, it can be extracted by doing ssh-keygen -yf ~/.ssh/id_rsa
)ssh-add -D
purges all cached keysssh -A
(A stand for agent forwarding).Local port forwarding is done with the -L
flag like this -
Alright, this is kinda fucky to read, but whats happening is basically
Basically, the host tries to access the remote service instead of us, and just forwards us the data on local_port
. And also, whatever we send to local_port
gets forwarded to remote_address:remote_port
We can also specify -R
for remote port forwarding. This is where we allow a remote server to access our local ports.
Example
If we have a webserver running on port 80 on our machine, and we have done ssh -R 9000:localhost:80 user@host
. Then any requests to the host at port 9000 will be forwarded to localhost on port 80.
The sed command is used to modify text content line by line.
Example
sed '1,4 s/x/y/5g' file
replaces every 5th and later occurences in the range of linenumbers 1 to 4.
Some things to note:
s
means substituted
means delete\b
means word boundaryThe awk command can split each line of input based on specifed delimiters into fields, and then perform functions on these fields. Some of the most commonly used functions are print
and boolean logic.
Example
This command would split each line into fields using ' ' as delimiter, and print only lines that have the third field equal to 1. The 3rd field of ps lax
is PID. So this would print -
4 0 1 0 20 0 22256 12408 - Ss ? 0:05 /sbin/init
The cut command is used to display a specific field (portion) of output given a delimiter. Given a delimiter, it splits up each line accordingly and numbers each field from 1.
-d
flag is used to specify delimiter-f
is used to specify field numberwahid@zephyrus-ubuntu:~$ echo 'f1,f2,f3:f4,f5,f6:f7,f8,f9' | cut -d: -f2
f4,f5,f6
This command output the number of lines, words and characters in a given file. It it almost always used with the corresponding flags -l
, -w
, -c
to output only numbers, surrounded by backticks.
Is basically like a T-fixture in plumbing. Redirects its input to STDOUT and a specified file.
The filesystem can be thought of as an explorable hierarchy that starts off at /
, the root directory. Each component of a pathname can only be 255 characters long. And the entire pathname can only be 4095 bytes long on Linux.
Think of our filesystem as a tree and a filesystem on another disk as a branch. We can add external filesystems to our "tree" by using the mount
command. mount
is a wrapper for filesystem specific mount commands.
Example usage
mount /dev/nvmen1p5 /mnt
This 'mounts' (or attaches) the filesystem at /dev/nvmen1p5
to /mnt
. So we can cd into /mnt
and browse it.
umount
is used to unmount a filesystem.
The contents of the file /etc/fstab
dictate what filesystems are to be mounted and fsck'ed at boot time. Turns out that fsck
is also a wrapper like mount
for filesystem specific fsck commands. These are present in the /sbin
directory.
wahid@zephyrus-ubuntu:~$ ls /sbin/ | grep fsck
dosfsck
e2fsck
fsck
fsck.cramfs
fsck.ext2
fsck.ext3
fsck.ext4
fsck.fat
fsck.minix
fsck.msdos
fsck.vfat
sbin and bin were used to differentiate between statically and dynamically linked binaries. But these days they have no real difference.
/bin
and /sbin
contain system critical utils/var
contains log files and other files that change rapidly/tmp
is for temp files/usr
is where standard important files are kept, but these are not system critical/lib
and /lib64
is for shared libraries. These are often symlinks to /usr/lib
and /usr/lib64
/etc
is for system critical configuration files/boot
is where the file containing the kernel is located along with the bootloader/dev
is a virtual fs??? Further study required
man hier
tells us general info about the filesystem hierarchy. It may not be followed on the system, it is just a general overview.
ls -la
lists out the file types and permissions. The characters given below can be used as a reference to this command's output.
Filetype | Symbol |
---|---|
Regular file | - |
Directory | d |
Character device file | c |
Block device file | b |
Local domain socket | s |
Named pipe | p |
Symlink | l |
These are just a blob of data, a series of bytes. They could be text, libraries, executables and so on.
A directory contains a list of references (hardlinks) to files. .
, ..
are special directories that mean current and parent directory. The name of a file is stored in the directory it is in, and not the file itself. So, it is possible for multiple directories to contain a reference to the same file.
A file with write permissions disabled can still be deleted, as it is the directory that contains the file name to data mapping. So, to delete a file, we would require write and execute permissions on the directory and not the file itself (read perms too if we do not know the file name).
A directory stores the name of a file and its inode number.
Related: Directory permission
Device files act as a gateway between the filesystem and device drivers. When a request is made to a device file, it just forwards the request to the appropriate device driver. Each device file has a major and minor device number, to represent which driver and which unit of that driver to refer to.
Example
/dev/tty0
and /dev/tty1
would have the same major number but different minor numbers.
Sockets allow processes to communicate. Also called Unix Domain Sockets (UDS), these are specifically used for communication between processes running on the same host OS. Unlike TCP packets which are used for communication between processes running on a network.
So, because UDS know they're on the same host, they can avoid a few checks that TCP/IP packets go through, and therefore be lighter and faster.[1]
A socket is also bidirectional, and can be used by multiple processes simultaneously.
Named pipes / FIFOs are basically super primitive local domain sockets. They have nothing to do with a network, are not bidirectional. We would require two pipes, one for read and one for write, for each client process that would want to communicate.[2]
Symlinks or softlinks are a pointer to a file. If the file is moved or is removed, then the symlink becomes invalid.
Theres a few different types of filesystems, each aiming to be good at specific things. ext4 is the standard in Debian and Ubuntu, while CentOS and Red Hat use XFS.
Filesystems like ext4, XFS are "traditional" in the sense that they do not handle stuff like volume management and RAID. Those things are handled separately, away from the filesystem. Non traditional filesytems would be ones like BTRFS and ZFS. They support integrated approahced to managing RAID, volumes, and even snapshots(?).
The ext4 filesystem is what is called a journaling filesystem. Journaling is somewhat like transactions in SQL. Whatever fs operation is to be performed is written to a journal, and then it is commited. Only then is the actual modification made.
If for some reason the actual operation failes, the filesystem can just look at the journal and safely reapply the last commit.
ext3 was the first to introduce journaling in the ext family. ext4 was just small revision over ext3 that extended a few limits
BTRFS and ZFS follow what is called Copy On Write. With COW, the entire filesystem moves from one consistent state to another. Instead of modifying data in place on the disk, an in-memory copy is modified and then written to some vacant block. And whatever was pointing to the original data is also rewritten to point to the new block. And so on, the parent's parent is rewritten up until the topmost level.
Package managers make managing software easier. Packages they install often generate new config files, add new groups.
The version number in the name of a package might not always match the version number of the actual software it contains.
Debian has dpkg
to install .deb
files. dpkg --install package.deb
installs the package if it is not already installed. If it is already installed, then dpkg removes the existing package before installing the new one.
Debian uses Advanced Package Tool (APT) as its package manager. APT started out at the Debian and dpkg side, but nowadays it also handles RPMs.
Sometimes an empty package is listed with a bunch of dependencies, so that all these dependencies can be installed under a single alias. For example, gnome-desktop-environment
is not actually an existing software package, but is a dummy package with a list of dependencies that are required to run GNOME.
The configuration file for apt is located at /etc/apt/sources.list
. This file contains information about where to find packages.
Each line is supposed to follow this format:
deb
, deb-src
, rpm
, rpm-src
universe
is one such component that has lots of open-source software. main
, multiverse
are some other examplesapt is actually a wrapper for a bunch of other low-level commands like apt-get
update
forces apt to download and update package information from configured repositoriesupgrade
installs available upgraded packages. If an older dependency is no longer required, it will NOT be removedautoremove
removes all orphan dependencies. If however, this orphan dependency is something that is useful (it could be a standalone package that we manually installed), then it can be marked with apt-mark
for autoremove
to exclude itinstall
searches for a given package name and installs itremove
just removes an installed package but leaves behind configuration filespurge
is remove
but also removes config files. NOT the config files in /home
. purge
also works on already remove
'd packagesEvery file has attributes. 9 of these are standard permission triplets - read, write and execute for the user (owner), group and others (everyone else).
They are structured as (rwx)(rwx)(rwx) for user, group and others in that order.
Each file also has 3 other bits -
s
implies that x
is also set. S
implies that only the set... bits are set and not the x bit.t
implies that x
is also set. T
implies that only the sticky bit is set and not the x bit.[3]s
, then it is the setuid bit.s
, then it is the setgid bit.s
.SUID: When set on an executable file, the file is executed with the permissions of the user (owner).
SGID: When set on an executable file, the file is executed with the permissions of the group of the user.
Sticky: Was used to retain programs in memory. Is now obsolete.
A directory just stores a filename and the file's inode number. Read permissions on a dir allow for accessing the filenames only. Write permissions allow for adding, renaming and deleting the files in it.[4]
The "execute" bit is reused as the search permission. When it is set, we are allowed to search for a file's inode. We can only read the files inside a directory, if we have read perms on the file itself and search (execute) perms on the directory. The execute bit is also required for the stat()
syscall, which is called during opening and deletion of a file.
SUID: Has no effect.
SGID: Files created in the directory will inherit the group of the directory.
Sticky: If set, only the owner and the super user are allowed to rename or delete files in it.
The chown
command is used to change the ownership (owner and group) of a file. Usual syntax is
The chmod
command is used to change the permissions of a file. The syntax is pretty memorable(u g o = user group other; r w x s = read write execute uid/gid).
The useradd
command is used to add an user. The default config for this command (such as the default shell) is located at /etc/login.defs
. Using -D
, we can change the default values.
Example
useradd -D -s /bin/tcsh
changes the default shell for any users that will be added in the future.
useradd -D
lists the default values. On my laptop, these are the defaults (haven't been modified)
adduser
is a more user friendly and interactive command (perl script really) that is available by default on Debian/Ubuntu.
Each process is assigned a unique ID by the kernel called a Process ID (PID). When a process wants to call a sub process, it must clone itself, and then exchange itself with a different process. This clone is called the child process, and the original process is the parent process. The child is given an attribute called the Parent PID (PPID) which is the PID of the parent process.
sudo
'ing a process, its EUID will be root's UIDA process's CPU time is determined based on how much CPU time it has most recently used, and how long it waited, and something called the nice value or niceness. The higher the niceness, the higher the priority.
We can observe two values - PR (priority) and (NI) niceness, when we use a process explorer like top
. PR and NI are related as - [5]
PR = 20 + NI
nice
'd process maps from 0 to 39, which are the rest of the 140 priorities.nice
command as show here -We can also set niceness to a running process with renice
as follows -
(The -p
flag is to specify that we will pass in PIDs).
We CAN set niceness to a negative value to make a process realtime, but this would require higher perms (sudo or root user). Real time processes will have negative PRs, like discussed earlier, but some of them might also have rt
as their PR, which means -100, or highest priority.
Processes with a known PID can be stopped using the kill
command. This command also takes in a signal as an argument that is sent to the process.
^C
sends a SIGINT
signal which is an interrupt signal, and the program can handle this interrupt; in most cases it aborts.
Processes can be stopped usually with a SIGINT
, if however that fails, we can use -
kill -9 <PID>
to send a SIGKILL
. If this fails for some reason, the only way to kill it properly is to reboot. For other possible signals, try kill -l
killall <name>
is very similar to kill
, but instead of PIDs it takes names and kills all processes by that name. Default signal is SIGTERM
but we can change it just like with kill.pgrep
or process grep, basically greps processes by name and lists their PIDs. pkill
kills them instead of listing them. We can also pkill
by owner of the process using the -u
flag and specifying user.^Z
sends a SIGTSTP
signal which suspends a process.
Suspended processes can be viewed using the jobs
command, and can be resumed to foreground or background with the fg
and bg
commands followed by the index that the jobs
command provides.
Processes can be monitored using the ps
command. This command's output is highly configurable and the most important and common usage is -
ps aux
, a
for all processes, x
for including processes without a control terminal, u
for user oriented outputu
flag is that it converts all the UIDs to usernames, which might be very slightly computationally expensive. So, a "more" efficient way is ps lax
which lists the output in (l
) long formatww
to the args to allow for wrapping
Processes that are started by the system's init system (systemd or init ...) don't have a control terminal.
Daemons startup by forking a child process and then the parent process is killed. The daemon is now an orphan and is adopted by the init system. Therefore, a daemon will also not have a control terminal.
strace
can be used to attach to a process by doing strace -p <PID>
and it outputs all syscalls made by that process.
cron
is used to schedule tasks. It is configured by modifying the cron table (crontab). When a cron service is active, it will schedule all tasks in the crontab. The actual location of crontabs depends on the implemenation that is being used.
Each line in crontab follows this format
minute hour day_of_month month day_of_week command
day_of_the_month
and month
day_of_week
starts with 0 as sunday*/5 9-16 * 1-5,9-12 1-5 ~/bin/i_love_cron.sh
This would run the script
When the kernel finishes its initialization process, it starts the init
process. init
is (was lol) a system management daemon. It has a number of important responsibilites including (but not limited to) -
fsck
'ing filesystems and mounting the filesystems in fstabRelated: initd
Mac used to use launchd until it eventually switched to systemd
Ubuntu up until 17.10 used upstart, also switched to systemd
Void Linux uses runit
systemd handles more than just processes. It handles network connections, kernel logs, logins. It has all the features that traditional init did, but adds on to it so much more and unifies them.
systemd, seemingly goes against UNIX philosophy which is to keep components as small as possible. So, of course there is an anti-systemd fandom. For the funny: https://without-systemd.org
systemd manages entities that it calls units. A unit can be a lot of things, so I won't list all of them here, but some of the important ones are a service, a socket, a device, a mount point.
We can differentiate them with their "extension". A service, for example would end with .service
.
Example unit file
[Unit]
Description=fast remote file copy program daemon ConditionPathExists=/etc/rsyncd.conf
[Service]
ExecStart=/usr/bin/rsync --daemon --no-detach
[Install]
WantedBy=multi-user.target
Unit files can be found at -
/usr/lib/systemd/system
/lib/systemd/system
/etc/systemd/system
(Highest priority)To manage systemd units, we have the systemctl
command. This can be used to -
start
and stop
a serviceenable
and disable
a service to start at bootlist-units
to list all installled units
--type=service
for example, to filter between unitsstatus
The Bourne shell is the original UNIX shell that was developed by AT&T. The sh
that we use today is the Alqmuist shell, which is a reimplementation. The Bourne again shell, bash
is pretty much the standard for both login shells and for scripting.
Every process has atleast three channels available - STDIN, STDOUT, STDERR. Which are assigned numbers called file descriptors, in this case 0, 1, 2 respectively. We are allowed to redirect these channels among processes in a number of ways by using a few symbols. [7]
<
connects STDIN to an existing file>
and >>
write and append to a file respectively. They connect STDOUT to a file.>&
is used to redirect both STDOUT and STDERR to the same location.2>
is used to redirect only STDERR
/dev/null
1>&2
redirects STDOUT to STDERR2>&1
redirects STDERR to STDOUT|
connects the STDOUT of one command to the STDIN of another&&
executes the second command if the first one succeeds||
executes the second command if the first one fails;
can be used to write a bunch of commands in one lineVariables are assigned as var='text'
. But they are referenced, prefixed with a $
sign, like $var
. When a variable has to be referenced inside a string, we additionally surround the variable name in {}
, like ${var}
.
Anything that is wrapped in backticks is treatead like a command, and the output of the command is substituted.
When a process starts, it receives all command line arguments along with these "pre-existing" variables called environment variables. Based on environment variables, a program can decide to change its behaviour.
Example
When the MOZ_ENABLE_WAYLAND
environment variable is set to 1
. Firefox will try to use wayland instead of x11.
The currently set environment variables can be listed with the printenv
command.
Example
wahid@zephyrus-ubuntu:~$ printenv
SHELL=/bin/bash
SESSION_MANAGER=local/zephyrus-ubuntu:@/tmp/.ICE-unix/1901,unix/zephyrus-ubuntu:/tmp/.ICE-unix/1901
QT_ACCESSIBILITY=1
COLORTERM=truecolor
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
...
The export
keyword can be used to "promote" a shell variable to an environment variable. Environment variables that are to be setup at login, are export
'ed in ~/.profile
or ~/.bash_profile
.
^P
in an active terminal session brings up the last used command. By using the fc
command, we can save our current command to a file, in our preferred editor (the editor is set with an env variable).
printf
respects escape characters unlike echo
and can be used whenever something has to be output.
read var
can be used to get a string of text from STDIN and store it in a variable var
.
Any arguments that were passed to the script can be accessed using $
followed by the index of the argument (starting from 1, 0 is the actual command that was used to invoke the script).
Important example
example arg1 arg2 arg3
$1
would be arg1, $2
would be arg2 and so on$#
contains the total number of arguments (doesn't count $0
)$*
contains all the arguments $?
contains the exit code of the previously executed command or scriptThe terminator for an if
statement if fi
. Else-if clauses are written as elif
and else clauses are just else
.
Syntax example
The []
are used to invoke test
. test
is a command that is used to compare two arguments. It returns the evaluated boolean as an exit code, 0 for false and 1 for true.
Example
However, nowadays, test
's functionality is built into the shell and /bin/test
is not actually invoked.
Comparision operators are not listed here as there are very few and easy to remember. One that should be noted are
-n x
evaluates to true if x is not null-z x
evaluates to true if x is null<
, >
when used must be double bracketed or escaped so they don't get misinterpreted as redirection operators-d
to check if file exists and is a directory-f
to check if file exists and is a regular file-r
to check if read perms-w
to check if write perms-s
to check if file exists and is not empty-e
to check if file exists-nt
and -ot
for newer than and older thanThe unusual thing to note here is that each pattern to be matched ends with a )
and after the case is handled, it is closed with ;;
. A case is compared with a specific pattern usinig the in
keyword. After all cases, have been handled, the statement is closed with esac
.
Example
for var in ...; do
syntax can be used for iterative loops. Space seperated arguments after the in
keyword are treated as a list and are iterated over as var
. A for loop is closed with a done
keyword.
If the in ...
part is left out, then the command line arguments are iterated over in a global for loop. If however, the for loop is part of a function, then the function arguments are iterated over.
The iterative list that is provided also supports wildcards just like the command line does.
Bash also supports traditional for loops like -
The general syntax is -
We can pass in a command to a while
clause, and it will loop until the command returns a non zero exit code. This allows us to do stuff like this for example -
To force arithmetic between variables instead of the default (concatenation) we use $((...)))
. $a+$b
would concat the two variables, whereas $((a+b))
would add them. As a general rule of thumb, use double parantheses whenever arithmetic is needed.
A shell script (sh) can consist of nothing but commands. The first line has what is called a shebang - #!
followed by the location of the interpreter that should be used to execute the script.
#!/bin/sh
would execute the script using sh
#!/usr/bin/env python
, for examplesh
or bash
or whatever interpreter we are using.Block devices are special types of files that allow for buffered access to any hardware. To list all block devices, we use the lsblk
utility.
Example from my laptop
Once we identify the device file corresponding to the disk we want to partition, we can use utilities like fdsik
, cfdisk
, gparted
.gparted
is a GUI based tool, it is also what Ubuntu's installer uses.
fdisk
is a safe bet, as most linux distros ship with it. Basic usage is fdisk /dev/sdx
fdisk
has a bunch of commands. These also have their shorthand notations, usually as one letter
g
: GPT partition tablen
: Create new partitionhelp
as a command+20G
for example, the last sector will be set to first_sector + 20GBytes
. Basically, +size
will create a new partition starting at the first sector we provide, that is as big as the size
we provide.Once we have partitioned the disk, we format each partition based on what its function should be. There are lots of different filesystem types, a couple of them are discussed at types of filesystems. Partitions are formatted with the mkfs.<type>
commands. A list of available commands can be found at /sbin
.
Example
To format a partition, say /dev/sda1
as ext4. We would do mkfs.ext4 /dev/sda1
.
For mounting partitions, refer mount.
External: https://serverfault.com/questions/124517/what-is-the-difference-between-unix-sockets-and-tcp-ip-sockets↩︎
External: https://unix.stackexchange.com/questions/75904/are-fifo-pipe-unix-domain-socket-the-same-thing-in-linux-kernel↩︎
External: https://wiki.archlinux.org/title/File_permissions_and_attributes↩︎
External: https://askubuntu.com/questions/656771/process-niceness-vs-priority↩︎
External: https://wiki.archlinux.org/title/cron#Crontab_format↩︎
External: https://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html↩︎