Everything Is A File (Live Demo)¶
Simple is beautiful¶
Important
One sometimes has to think more to reach simplicity.
This pays off a thousand times.
Ok: a File is a File¶
A file is a file. That’s simple.
There are tools explicitly made to read and write files, everybody can use these.
$ echo Hello > /tmp/a-file
$ cat /tmp/a-file
Hello
Is a Serial Interface (UART) a File?¶
Why not? Data go out and come in!
$ echo Hello > /dev/ttyUSB0
$ cat /dev/ttyUSB1
Hello
Pseudo Terminals¶
Terminals
History: login via a hardware terminal, connected through a serial line
Terminal (TTY) layer (in the kernel) implements session management
Pseudo Terminal: software instead of cable
Consequentially, output to a pseudo terminal is like writing to a cable, err, file.
$ echo Hello > /dev/pts/0
Disks and Partitions¶
# cat /proc/partitions
major minor #blocks name
8 32 2006854 sdc
8 33 2006823 sdc1
# cp /dev/sdc1 /Backups/USB-Stick
# mount -o loop /Backups/USB-Stick /mnt
/proc
and /sys
¶
Kernel has variables in memory that configure certain aspects of its operation
Most of these variables are exposed as files
⟶ Virtual file systems:
sys
andproc
$ cd /proc/$$ # ... deserves a bit of explanation though :-)
# echo disk > /sys/power/state
Pseudo Devices¶
/dev/null
: trash can, swallowing everything you write to it)x$ echo hallo hallo $ echo hallo > /dev/null
/dev/zero
: insane amount of NULL-bytes$ ls -l /dev/zero crw-rw-rw-. 1 root root 1, 5 Mar 7 12:10 /dev/zero $ cat /dev/zero > /dev/null
$ dd if=/dev/zero of=/tmp/1MibFS.fat count=1024 bs=1024 $ ls -lh /tmp/1MibFS.fat -rw-rw-r--. 1 jfasch jfasch 1.0M Mar 7 17:32 /tmp/1MibFS.fat $ mkfs.vfat /tmp/1MibFS.fat
/dev/random
: kernel, respectively drivers, collect entropy from certain kinds of interrupts.$ ls -l /dev/random crw-rw-rw-. 1 root root 1, 8 Mar 7 12:10 /dev/random $ cat /dev/random