My two cents
A lot of people don't understand the full meaning of this concept.
- The root of everything is
/
.
- From there you find directories called
bin
for binaries,
dev
for devices,
etc
for configuration file,
lib
for libraries,
tmp
for temporaries (the content of this will be destroyed each reboot),
proc
under linux, hold access point to kernel pointers/variables,
sys
under recent (I don't remember wich version) linux, for entry point to system drivers,
var
for variables files (DB, mails, apt, rpm)...
... You may look, when using ls -l
:
ls -ld /etc /etc/issue
drwxr-xr-x 240 root root 20480 Oct 7 23:12 /etc
-rw-r--r-- 1 root root 27 Apr 10 2021 /etc/issue
The 1st character mean:
d
for directories
-
for standard file
But if you
ls -dl /bin/sh /dev/tty1 /dev/ttyS0 /dev/?da /dev/sr0
lrwxrwxrwx 1 root root 4 Dec 10 2020 /bin/sh -> dash
brw-rw---- 1 root disk 8, 0 Aug 30 18:06 /dev/sda
brw-rw----+ 1 root cdrom 11, 0 Aug 30 18:10 /dev/sr0
crw--w---- 1 root tty 4, 1 Aug 30 18:08 /dev/tty1
crw-rw----+ 1 root dialout 4, 64 Aug 30 18:06 /dev/ttyS0
The 1st character mean:
l
for symbolic link (pointing to /bin/dash
)
b
for block devices, like hard disk or cd rom
c
for character devices, like serial (COM1 under window), many USB devices, etc...
Then everything is a file mean, you could address a disk or a partition, a printer, a camera, or audio device, or... in same way you address a file!
For sample:
Simple command like:
cat /dev/sr0 >/path/to/diskImage.iso
is enough to create a disk image from a CDROM.
cat /path/to/diskImage.iso >/dev/sdX
will create an USB stick from ISO image... But will overwrite potential content of sdX
with content of image file... You'd better ensure to point correct device!!!
More?
mkfifo /tmp/fifotest
ls -l /tmp/fifotest
prw-r--r-- 1 user user 0 Oct 7 22:09 /tmp/fifotest
I won't explain here how to use a fifo nor a socket... If you host mysqld
:
ls -l /run/mysqld/mysqld.sock
srwxrwxrwx 1 mysql mysql 0 Aug 27 18:33 /run/mysqld/mysqld.sock
p
for fifo...
s
for socket...
Pseudo entries, bash feature
Under recent bash, you could access TCP connection via pseudo /dev/tcp/ip_address/tcp_port
devices. For sample this open a connection on port 80
at `www.google.com:
exec {wget}<>/dev/tcp/www.google.com/80
Then a minimal request could look like:
printf '%s\r\n' 'GET / HTTP/1.0' Host: www.google.com '' >&$wget &&
while read -ru $wget line;do
[[ $line =~ Set-Cookie* ]] && echo $line ;done; exec {wget}>&-
( This will print an useless cookie )
Then
Everything you want to do, you just have to take some(s) input, apply some(s) filter and transmit to some(s) output.
That's all.
Other OS
Mac
As Mac OS is based on Un*x, from Mac Os X
, they use near same approach.
Windows
I remember, more than 30 years ago: I was impressed how many money could represent command like cat
when dealed under Windows to permit some users to make CD images or save his hard drive!!!
Everything you want to do under Window depend on different libraries, with different meaning, syntax etc.
Note
In this answer, I don't tell about hard links, mount point, socket, like a lot of other basis concept making POSIX the must!