Unix
A family of operating systems that derive from the original AT&T's Unix.
Unix philosophy:
- Write programs that do one thing and do it well
- Write programs to work together
- Write programs to handle text streams, because that is a universal interface
Learn
POSIX
Portable Operating System Interface. A standard for maintaining compatibility between operating systems.
Defines:
- System and user-level APIs
- Command line shell and utility interfaces
See also Single UNIX Specification.
Sockets
A Unix socket is a communication endpoint for exchanging data between processes. The difference between Unix sockets and network sockets is that the latter can exchange data over the network. Unix sockets are faster, which makes them the better option for communication on the same host.
Unix sockets are a part of the POSIX standard.
Standard files
- Input:
stdin
(0) - Output:
stdout
(1) - Error output:
stderr
(2)
Redirect:
> log.txt
:stdout
to file2> log.txt
:stderr
to file&> log.txt
: both to file2>&1
:stderr
tostdout
Soft and Hard links
A soft link is another file that contains the path to the original file. If the target is moved or deleted, the link "hangs". The closest analogy is pointers in programming.
💡 Hint
Usereadlink
to get the path a soft link points to.
A hard link is a direct reference to the actual data on disk (called inode). Every filename is a hard link by design. Hard links allow multiple files to reference the same content without wasting disk space. The actual data won't be deleted until all the hard links pointing to it are deleted.
✏️ Note
mv
just changes the hard link without touching the inode.
💡 Hint
Usels -i
to printinode
numbers.
Filesystem
/etc
: system-wide config files/etc/hosts
: DNS database/etc/passwd
: users database/etc/group
: groups database/etc/shells
: allowed shells/etc/paths
: system-wide paths (read by all shells)/dev
: device files/dev/tty
: current terminal session (same astty
)/dev/null
: input discard
Directory permissions
For directories, permission bits have different meanings:
(r)
: the ability to list files in the directory(w)
: the ability to create/rename/delete files in the directory (only if(x)
is set)(x)
: the ability tocd
into and access files in the directory
Because of the (x)
meaning, directories are usually created with 0755
instead of 0644
.
XDG Base Directory
$XDG_CONFIG_HOME
: user-specific config files (if not set,$HOME/.config
should be used)
Cron
cron
is a general name for the service that runs scheduled jobs.
crond
is a daemon that runs in the background and reads crontab files.
crontab
is a tool to edit crontab files.