paint-brush
5 Things You Should Know About Linux by@dejanualex

5 Things You Should Know About Linux

by dejanualexJuly 7th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Everything is a file design: Files are files, devices drivers are files. Everything, whether a plain-text file, block, character special device driver, or kernel state behaves a lot like a file. Every process has a file descriptor associated with it, a process can open all sorts of files like /dev files, UNIX Sockets, Network sockets, Library files /lib /lib64, so the latter becomes:. The latter is the latter, the latter is:. The Linux philosophy is that Linux processes are visualized as a running instance of a program.
featured image - 5 Things You Should Know About Linux
dejanualex HackerNoon profile picture

When you start working with Linux, it's good to have a rough view with regard to Linux philosophy.

Disclaimer: This is my own highly opinionated view.

1) Everything is a file design

  • Files are files, devices drivers are files, directories, system configuration, kernel parameters, and... even processes are all represented as files on the filesystem.
  • Everything, whether a plain-text file, block, character special device driver, or kernel state behaves a lot like a file.
# check how shell was started, using the PID of the current process, and leveraging everything is a file design
ls -l /proc/$$/cmdline

# check the file descriptors of it
ls -l /proc/$$/fd

2) Each command does one thing and one thing very well.

  • Finding things is very easy, being a d (directory) c (character special file), b (block special file), l (symbolic link), p (named pipe), s (socket), and f (normal file).
find <location> -name <file_name> -type <file_type>
  • Measuring things is very easy. For example:
# Calculate size of each of the system top-level dirs
 du --max-depth=1 -hx /

3) Everything running is a process

  • In a basic form, Linux processes can be visualized as a running instance of a program.
  • Every process is started by a parent, except the init process (on most distributions, systemd is the parent of all other processes directly or indirectly) which is started by the Linux kernel and has a PID of 1.
# check which process has PID 1
ps -p 1

# list all files opened by a process
lsof -p 1

  • Every process has a file descriptor associated with it, a process can open all sorts of files like /dev files, UNIX Sockets, Network sockets, Library files /lib /lib64, so the latter becomes:
# check file descriptors
ls -l /proc/1/fd

4) Pipelines allow composition

  • Anything that can be read or written. For any process, we have three standard file things: what it can read (stdin) and where it can write (stdout and stderr).
# find PID of python process and kill it
ps aux | grep python | grep -v grep | awk '{print $2}' | xargs kill

5) Shell comes in multiple flavors

We have sh (Bourne shell), csh (C shell), bash (Bourne-again shell), ksh (Korn shell), and last but not least zsh.