1
0
Fork
You've already forked LPIC-Notes
0
My Notes for LPIC Exams
2026年03月29日 07:39:47 +02:00
lpic-101_notes.html progress.. 2026年03月21日 09:47:08 +01:00
lpic-101_notes.org moep 2026年03月29日 07:39:47 +02:00
README.md okay that's about it 2026年03月29日 07:38:38 +02:00

m0fr1m's LPIC-101 Notes

Disclaimer: These notes merely represent my knowledge gaps or more or less interesting new learnings from the LPIC-101 Learning Materials v5.0. They are not intended to be a representation of the complete content relevant in the exams.

My Current Dumb Bookmark: page 86

101 System Architecture

101.1 Determine and configure hardware settings

Key Knowledge areas

  • Enable and disable integrated peripherals.
  • Differentiate between the various types of mass storage devices.
  • Determine hardware resources for devices.
  • Tools and utilities to list various hardware information (e.g. lsusb, lspci, etc.).
  • Tools and utilities to manipulate USB devices.
  • Conceptual understanding of sysfs, udev and dbus.

Partial List of cmds & files used

  • sys
  • proc
  • dev
  • ☒ modprobe
  • ☒ lsmod
  • ☒ lspci
  • ☒ lsusb

Learnings

  • BIOS = Basic Inpuc Output System
  • UEFI = Unified Extensible Firmware Interface (since mid early 2000s)
  1. lspci

    • Output of a simple lspci

      00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 09)
      00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 09)
      00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 09)
      [...]
      
    • show info only about a certain device using its unique address

      $ lspci -s 00:00.0 -v
      00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 09)
       Subsystem: Apple Inc. Device 011a
       Flags: bus master, fast devsel, latency 0
       Capabilities: <access denied>
       Kernel driver in use: hsw_uncore
      
    • only show info about the associated kernel modules lspci -s 00:00.0 -k:

      $ lspci -s 00:00.0 -k
      00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 09)
       Subsystem: Apple Inc. Device 011a
       Kernel driver in use: hsw_uncore
      
  2. lsusb

    a simple lsusb lists all usb devices with their IDs

    $ lsusb
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 002: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
    Bus 001 Device 003: ID 05ac:0290 Apple, Inc. Apple Internal Keyboard / Trackpad
    Bus 001 Device 006: ID 05ac:828f Apple, Inc. Bluetooth USB Host Controller
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    

    the lspci counterpart for lsusb for listing individual device details is

    $ lsusb -v -d 1d6b:0002
    Bus 001 Device 006: ID 05ac:828f Apple, Inc. Bluetooth USB Host Controller
    Negotiated speed: Full Speed (12Mbps)
    Device Descriptor:
     bLength 18
     bDescriptorType 1
     bcdUSB 2.00
     bDeviceClass 255 Vendor Specific Class
     bDeviceSubClass 1 [unknown]
     bDeviceProtocol 1 
    [...]
    

    however this does not show one crucial info: a potentially used kernel module! to show this run lsusb -t to show the device hirarchy tree:

    $ lsusb -t
    /: Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/9p, 480M
     |__ Port 003: Dev 002, If 0, Class=Hub, Driver=hub/3p, 12M
     |__ Port 003: Dev 006, If 0, Class=Vendor Specific Class, Driver=btusb, 12M
     |__ Port 003: Dev 006, If 1, Class=Wireless, Driver=btusb, 12M
     |__ Port 003: Dev 006, If 2, Class=Vendor Specific Class, Driver=btusb, 12M
     |__ Port 003: Dev 006, If 3, Class=Application Specific Interface, Driver=[none], 12M
     |__ Port 005: Dev 003, If 0, Class=Human Interface Device, Driver=usbhid, 12M
     |__ Port 005: Dev 003, If 1, Class=Human Interface Device, Driver=usbhid, 12M
     |__ Port 005: Dev 003, If 2, Class=Human Interface Device, Driver=bcm5974, 12M
    /: Bus 002.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    

    In the Driver field we can find the associated kernel module for each dev! It is also possible to query devices using lsusb -s Bus.Port:Dev, very similarly to lspci.

  3. /proc vs. /sys

    • /sys more hardware related stuff
    • /proc also other kernel structures like process info etc.

Exercises

nothing of great interest here

Key Takeaways for me

  • lsusb -t is very handy for indentifying kernel modules associated with usb devices
  • lspci -s 00:00.0 -k or -v also lists the kernel module use for a single dev
  • to achieve the same with lspci one has to use lspci -v <address> where address is retrieved from a call to lspci
  • lsmod shows all currently loaded modules
  • lsmod | grep -i snd_hda_intel lists all modules using snd_hda_intel module
  • modprobe -r <module_name> unload a module (that is currently not being used by any process or module)
  • modprobe <module_name> load a module
  • modinfo get all info about a module
  • modinfo -p get only info about a modules parameters (nice for setting them as kernel boot params)

101.2 Boot the system

Key Knowledge areas

  • Provide common commands to the boot loader and options to the kernel at boot time.
  • Demonstrate knowledge of the boot sequence from BIOS/UEFI to boot completion.
  • Understanding of SysVinit and systemd.
  • Awareness of Upstart.
  • Check boot events in the log files.

Partial List of cmds & files used

  • ☒ dmesg
  • ☒ journalctl
  • ☒ BIOS
  • ☒ UEFI
  • ☒ bootloader
  • ☒ kernel
  • ☒ initramfs
  • ☒ init
  • ☒ SysVinit

Learnings

  1. BIOS and UEFI

    • BIOS assumes firt 440 bytes in first storage dev(according to the order defined in BIOS config) contain the bootstrap aka first stage of the bootloader
    • the first 512B of a dev a called the MBR. so 512 - 440 = 72B are left for the partition table
    • UEFI does not need MBR
    • EFI partition has to be FAT12/16/32 or ISO-9660. on the partition: EFI applications. Partition aka EFI System Partition (ESP)
    • on the ESP: `EFI/` dir contains all EFI-apps
    • EFI introduces Secure Boot: only EFI-apps signed can be executed
  2. The Bootloader

    • BIOS-systems: `Shift`-key brings up grub menu. UEFI: `Esc`
    • Some kernel boot params:
      • mem: e.g. mem=512M limit amount of RAM available
      • maxcpus: limit amount of CPUs (used in VMs a lot)
      • quiet: hide boot msgs
      • vga: e.g. vga=ask shows list of available video modes
      • root: e.g. root=/dev/sda set root partition
      • rootflags: mount options for root partition
      • ro/rw: initial mount root fs ro/rw
    • add kernel params to /etc/default/grub's GRUB_DEFAULT_LINUX entry && run grub-mkconfig -o /boot/grub/grub.cfg
    • kernel params used to boot the current system are available at run-time under /proc/cmdline !!!
  3. System Initialization

    • bootloader loads kernel into RAM
    • kernel opens initramfs which is a temporary root fs containing the modules the kernel needs to access the real root fs
    • when root fs available: kernel mounts everything in /etc/fstab
    • kernel runs init & removes initramfs from RAM
  4. Initialization Inspection

    • systemd -> there will also be journalctl
    • journalctl --list-boots
    • journalctl -b -1 last boots logs

Key Takeaways for me

  • journalctl --list-boots lists available logs from past boots
  • journalctl -b -1 last boots logs
  • journalctl -D /path/to/other/journal/dir open journalctl for different then standard dir
  • dmesg -H for human readable (especially the timestamps) output

101.3 Change runlevels...

Key Knowledge areas

  • Set the default runlevel or boot target.
  • Change between runlevels / boot targets including single user mode.
  • Shutdown and reboot from the command line.
  • Alert users before switching runlevels / boot targets or other major system events.
  • Properly terminate processes.
  • Awareness of acpid.

Learnings

  1. SysVinit

    1. Runlevels

      • 0: system shutdown
      • 1/s/single: single user / maintenance mode, no network & other things
      • 2,3,4: most common 3, Multi-User mode, no graphical
      • 5: like 4 + graphical, standard on desktop PCs
      • 6: restart
    2. /etc/inittab

      init looks up what to do in /etc/inittab. init can also get runvlevel info via kernel param.

      Syntax of /etc/inittab:

      id:runlevels:action:process
      

      the action field tells init what to do with the command, f.ex:

      • boot: process executed during system initialization
      • wait: init should wait for the process to finish
      • etc.

      here a complete inittab:

      # Default runlevel
      id:3:initdefault:
      # Configuration script executed during boot
      si::sysinit:/etc/init.d/rcS
      # Action taken on runlevel S (single user)
      ~:S:wait:/sbin/sulogin
      # Configuration for each execution level
      l0:0:wait:/etc/init.d/rc 0
      l1:1:wait:/etc/init.d/rc 1
      l2:2:wait:/etc/init.d/rc2
      l3:3:wait:/etc/init.d/rc 3
      l4:4:wait:/etc/init.d/rc 4
      l5:5:wait:/etc/init.d/rc 5
      l6:6:wait:/etc/init.d/rc 6
      # Action taken upon ctrl+alt+del keystroke
      ca::ctrlaltdel:/sbin/shutdown -r now
      # Enable consoles for runlevels 2 and 3
      1:23:respawn:/sbin/getty tty1 VC linux
      2:23:respawn:/sbin/getty tty2 VC linux
      3:23:respawn:/sbin/getty tty3 VC linux
      4:23:respawn:/sbin/getty tty4 VC linux
      # For runlevel 3, also enable serial
      # terminals ttyS0 and ttyS1 (modem) consoles
      S0:3:respawn:/sbin/getty -L 9600 ttyS0 vt320
      S1:3:respawn:/sbin/mgetty -x0 -D ttyS1
      
      • on changes to inittab telinit q should be run for reloading.
      • with runlevel you get the current runlevel.
      • This is all obsolete i'd say
  2. systemd

    • services = units in systemd speech
    • a unit consists of a name, a type and a configuration file
    1. 7 distinct types of units

      1. service most common. can be initiated, interrupted and reloaded
      2. socket can be any socket. all socket units have corresponding service unit loaded when the socket receives a request
      3. device a device will only be taken as a systemd unit if a udev rule for this purpose exists.
      4. mount mount point def in fs
      5. automount
      6. target a grouping of other units manages as a single unit
      7. snapshot saved state of the systemd manager
    2. typical commands

      systemctl... + status ... is-active, enable, disable, is-enabled

    3. more commands

      • systemctl isolate multi-user.target manually alternates to this target
      • systemctl set-default multi-user.target changes the link /etc/systemd/system/default.target points to. usuallhy graphical.target
      • systemctl get-default Show default target
      • systemctl list-units[-files] --type=target yep
  3. upstart

    ignore

Key Takeaways for me

  • a unit consists of a name, a type and a configuration file
  • 7 types it seems there are more nowadays: also timer and slice
  • systemctl isolate multi-user.target manually alternates to this target
  • systemctl set-default multi-user.target changes the link /etc/systemd/system/default.target points to. usuallhy graphical.target
  • systemctl get-default Show default target
  • systemctl list-units[-files] --type=target yep

102 Linux Installation and Pkg Mgmt

102.1 Design hard disk layout

Key Knowledge areas

  • Allocate filesystems and swap space to separate partitions or disks.
  • Tailor the design to the intended use of the system.
  • Ensure the /boot partition conforms to the hardware architecture requirements for booting.
  • Knowledge of basic features of LVM.

Learnings

  • modern distro mount stuff automatically under /media/USER/LABEL
  • ESP = EFI System Partition
  • swap partition size
    • <2GB of RAM -> 2x the amount of RAM, for hibernation 3x
    • 2-8GB -> equal the amount of RAM, 2x RAM for hibernation
    • 8-64GB -> at least 4GB, for hibernation 1.5x RAM
  1. LVM

    • Basic unit: Physical Volume, a block device on the system
    • PVs are grouped in to Volume Groups, which abstract the undelying devices and are seen as a single logical device with the combined storage capacity of the single PVs
    • VGs are divided into extents. Extents on a PV are Physical Extents, extents on a Logical Volume are Logical Ext., each logical extent is mapped to a physical.
    • LVs are the partitions
    • The size of a Logical Volume, as specified during its creation, is in fact defined by the size of the physical extents (4 MB by default) multiplied by the number of extents on the volume. From this it is easy to understand that to grow a Logical Volume, for example, all that the system has to do is add more extents from the pool available in the VG.
    • After creation a LV can found under /dev/VGNAME/LVNAME

Exercises

Key Takeaways for me

  • where is the EFI partition usually mounted? /boot/efi
  • how is the size of a LV defined? by the size of the physical extents times the number of extents in the volume

102.2 Install a boot manager

Key Knowledge areas

  • Providing alternative boot locations and backup boot options.
  • Install and configure a boot loader such as GRUB Legacy.
  • Perform basic configuration changes for GRUB 2.
  • Interact with the boot loader.

Partial List of cmds & files used

  • menu.lst, grub.cfg and grub.conf
  • grub-install
  • grub-mkconfig
  • MBR

Learnings

  • again MBR: first 512 bytes of the primary disk. bootstrap code aka bootloader + partition table
  • first MBR bootloader loads secondary bootloader from disk in the 32KB range after MBR and before first partition.
  • MBR has limitations: originally max 4 primary, later 3 primary + 1 extended with logical partitions, nax 2TB disk size
  • GPT = GUID Partition Table, part of UEFI standard to the help!
  • still compatible with BIOS machines
  • secondary loader of GRUB stored in a special BIOS boot partition.
  • on UEFI systems GRUB is loaded either from grubia32.efi or grubx64.efi from the ESP (/boot/EFI ;)
  1. /boot

    1. possible content (out-dated)

      • Kernel config file config-VERSION
      • System map symbol table for debugging System.map...
      • Linux kernel vmlinux-...
      • Initial ramdisk initrd..
      • /boot/grub/menu.lst DEPRECATED!!! only grub legacy!
      • /boot/grub/grub.cfg is the GRUB2 config file!
  2. installing grub2

    • check for boot partition on system using fdisk -l /dev/sda
    • mount the boot partition, e.g. to /mnt/tmp
    • grub-install --boot-directory=/mnt/tmp /dev/sda
  3. configuring grub2

    • /boot/grub/grub.cfg is automatically generated
    • edit /etc/default/grub instead and then run update-grub
    • options in /etc/default/grub
      • GRUB_DEFAULT the default menu entry to boot, either a number 0,1,.. or name like debian, or saved
      • GRUB_SAVEDEFAULT if set to true the default boot option will always be the last one selected
      • GRUB_TIMEOUT: 0 boot immediately, -1 wait until user selects sth
      • GRUB_CMDLINE_LINUX kernel params that will be added to every kernel
      • GRUB_CMDLINE_LINUX_DEFAULT by default always a normal and a recovery menu entry are generated. this params only go to default entry
      • GRUB_ENABLE_CRYPTODISK check for encripted disks & make booting them work
  4. managing menu entries

    • update-grub scans for kernels and OSes on the machine and them to menu automatically

    • for manual entries edit files in /etc/grub.d

    • these files should be executable, and are processed in numerical order

    • basic syntax for a menu entry:

      menuentry "Default OS" {
       set root=(hd0,1)
       linux /vmlinuz root=/dev/sda1 ro quiet splash
       initrd /initrd.img
      }
      
    • to set root partition by UUID use search --set=root --fs-uuid UUUUIIIIDDD instead of set root..

    • find UUID by ls -l /dev/disk/by-uuid

  5. the grub2 shell

    • press c to enter grub2 shell from boot menu
    • use ls (hd0,msdos1) or the like to find the kernel, then
    • set root=(hd0,msdos1)
    • linux /vmlinuz root=/dev/sda1
    • initrd /initrd.img
    • boot

    so in principle enter the same stuff like in a menuentry.

  6. boot from rescue shell

    • set prefix=(hd0,msdos1)/boot/grub
    • insmod normal
    • insmod linux
    • then proceed like in the normal shell

Exercises

Key Takeaways for me

  • press c to enter grub2 shell from boot menu
  • use ls (hd0,msdos1) or the like to find the kernel, then
  • set root=(hd0,msdos1)
  • linux /vmlinuz root=/dev/sda1
  • initrd /initrd.img
  • boot

102.3 Manage shared libs

Key Takeaways for me

just a quick recap, as i know most of this:

  • conf files in /etc/ld.so.conf.d/ include the abs path to dirs containing shared libs
  • ldconfig must be run every time conf-files change
  • use LD_LIBRARY_PATH env var for temporarily adding libs
  • ldd!

102.4 Use of debian pkg manager

Key Takeaways for me

  • dpkg -I package.deb for inspecting pkgs seems quite nice
  • dpkg -r / -P for removing / purging pkgs
  • dpkg --get-selections get list of installed pkgs on system
  • dpkg -L unrar get list of files installed by pkg unrar
  • dpkg-query -S /usr/bin/unrar-nonfree find out which pkg owns a specific file on system
  • dpkg-reconfigure runs the post-install configuration step again
  • when installing with Apt = Advanced Package Tool deb-files are downloaded to /var/cache/apt/archives to clean that dir from time to time use apt clean.
  • apt-cache search / show are the same as apt search / show
  • /etc/sources.list ...
  • apt-file search libSDL2.so does the same thing like dpkg-query but also in uninstalled pkgs.

102.5 RPM package manager

Key Takeaways for me

  • rpm -i PKGNAME.rpm install pkg
  • use rpm -ivh PKGNAME.rpm for progress bar and verbosity
  • rpm -U PKGNAME upgrade pkg
  • rpm -e erase aka remove a pkg
  • rpm -qa "query all" lists all pkg installed on your system
  • rpm -qi pkg "query info" about a pkg
  • rpm -ql unzip list files installed by pkg
  • do the same as the above two commands on a rpm-file: rpm -qip pkg.rpm and rpm -qlp pkg.rpm
  • dnf list --installed list installed pkgs on system
  • dnf repolist (--enabled) list available (enabled) repos
  • dnf config-manager --add-repo URL add a repo
  • dnf config-manager --set-enabled REPO_ID
  • repo files for dnf are stored in /etc/yum.repos.d/

102.6 Linux as a virtualization guest

Learnings

  1. 3 Types of VMs

    • Fully virtualized no additional drivers for the guest OS necessary. guest is unaware of running in a VM. Intel VT-x or AMD-V CPU-extensions needed.
    • Paravirtualized guest is aware of running in a VM modified kernel & guest drivers help the guest use resources of the hypervisor. better performance
    • Hybrid use the best of both worlds to achieve near native I/O performance example: virtio on KVM
  2. qemu / libvirt

    • networks and VMs and everything else is saved in XML files under /etc/libvirt/qemu/networks/
    • 2 types of disk-images
      • COW = Copy On Write upper size limit, but data is only written to image when needed
      • RAW consumes the full size no matter how much data has been written to it. slightly more performant as no size-monitoring has to be done during write
  3. The D-Bus Machine ID

    • durin linux installation a UUID called the D-Bus Machine ID is generated on every Linux system. No 2 virtual machines running on the same hypervisor can have the same ID
    • dbus-uuidgen --ensure checks if the current system has an ID
    • dbus-uuidgen --get get the ID which is located at /var/lib/dbus/machine-id and a sym-link to /etc/machine-id
    • to generate a D-Bus ID: sudo dbus-uuidgen --ensure=/etc/machine-id

Key Takeaways for me

  • Hypervisor is the name of the software allowing to run processes that contain fully emulated computer systems.
  • The virtual machines are called Guests of the hypervisor.

103 GNU- und Unix-Befehle

103.1 & 103.2 cmds, cmds...

grep vs. sed

You can easily emulate the behavior of grep using sed:

$ cat input.txt
miep
moep
marp
bla
foo
$ grep miep input.txt
miep
$ sed -n /miep/p < input.txt
miep

Therefore sed -n /pattern/p prints only the lines matching pattern. to invert the logic here one can use sed -n /pattern/d. This omitts the lines matching pattern.

more sed-fu

  • sed -i.bak 's/cat/dog/' bla.txt will in-place sed but create a backup file before this

the 'explore /etc/passwd'-exercise

$ cat passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
nvidia-persistenced:x:121:128:NVIDIA Persistence Daemon,,,:/nonexistent:/sbin/nologin
libvirt-qemu:x:64055:130:Libvirt Qemu,,,:/var/lib/libvirt:/usr/sbin/nologin
libvirt-dnsmasq:x:122:133:Libvirt Dnsmasq,,,:/var/lib/libvirt/dnsmasq:/usr/sbin/nologin
carol:x:1000:2000:Carol Smith,Finance,,,Main Office:/home/carol:/bin/bash
dave:x:1001:1000:Dave Edwards,Finance,,,Main Office:/home/dave:/bin/ksh
emma:x:1002:1000:Emma Jones,Finance,,,Main Office:/home/emma:/bin/bash
frank:x:1003:1000:Frank Cassidy,Finance,,,Main Office:/home/frank:/bin/bash
grace:x:1004:1000:Grace Kearns,Engineering,,,Main Office:/home/grace:/bin/ksh
henry:x:1005:1000:Henry Adams,Sales,,,Main Office:/home/henry:/bin/bash
john:x:1006:1000:John Chapel,Sales,,,Main Office:/home/john:/bin/bash
  1. which users have access to bash shell?

    for example:

    $ cat passwd | grep bash | cut -d: -f1
    
  2. List all users in group 1000 with sed

  3. List all users of gid 1000 with their full name

    sed -n 's/^\(.\+\):.\+:.\+:1000:\([A-Za-z ]\+\).\+$/2円/p' < passwd
    

    using sed and cut:

    sed -n 's/^\(.\+\):.\+:.\+:1000:\([^:]\+\):.\+$/2円/p' < passwd | cut -d, -f1
    

    or another one

    sed -n '/:[[:digit:]]\+:1000/p' < passwd | cut -d: -f5 | cut -d, -f1
    
  4. Random sort and win

    Once more using the mypasswd file from the previous exercises, devise a Bash command that will select one individual from the Main Office to win a raffle contest. Use the sed command to only print out the lines for the Main Office, and then a cut command sequence to retrieve the first name of each user from these lines. Next you will want to randomly sort these names and only print out the top name from the list.

    sed -n '/Main Office/p' < passwd | cut -d: -f5 | cut -d ' ' -f1 | sort -R | head -n 1
    
  5. paste & names.csv

    $ echo "First,Last,Pos" > names.csv
    $ sed -n /Office/p < passwd | cut -d: -f5 | cut -d ' ' -f1 > first
    $ sed -n /Office/p < passwd | cut -d: -f5 | cut -d ' ' -f2 | cut -d, -f1 > last
    $ sed -n /Office/p < passwd | cut -d: -f5 | cut -d ' ' -f2 | cut -d, -f2 > pos
    $ paste --delimiters ',' first last pos >> names.csv
    

103.3.1 file management

ls

meaning of first char in ls -l output:

  • c special file
  • - regular file
  • d dir

file globbing

3 types of globbing

  • * zero or more repetitions of any char
  • ? single occurrence of any char
  • [a-z] any single character specified

103.3.2 find, tar & dd

find

  • find . -type f -name "example" find all files of type "file" and name "example" in .
  • types:
    • f regular file
    • d dir
    • l symbolic link
  • -iname like but case-insensitive
  • -not return results that do not match case
  • -maxdepth N maximum dir depth
  • -mtime 7 modification time during the last 7 days
  • sudo find /var -size +2G find by size!!!
  • or even ranges: find ~ -size +100M -size -1000M -exec ls -lh '{}' \;

103.4 streams, pipes, redirects

  • all processes stdout, stdin and stderr is also available under /dev/stdout, /dev/stdin and /dev/stderr
  • aha! major learning! the syntax in 2>&1 has to be like this because prefixing a number with an ampersand like in &1 denotes a file descriptor!!!
  • Another major Learning: you cannot redirect stderr to stdin of another process directly. you first need to 2>&1.
  • with set -o noclobber redirecting output to a existing file fails. good to prevent overwriting things. appending using >> still works.
  • the same fd can be used for reading an writing 3<> bla.txt
  • The HERESTRING method: wc -c <<< "moepmoepmoep"

xargs

  • xargs is the tool to run commands on the output of another process like this: find /usr/share/icons -name 'debian*' | xargs identify -format "%f: %wx%h\n"
  • if the paths have space chars the null character must be used as field separator: find . -name '*avi' -print0 -o -name '*mp4' -print0 -o -name '*mkv' -print0 | xargs -0 du | sort -n
  • the files / args read from stdin can be assigned a variable name (PATH in this example) xargs -0 -I PATH mv PATH ./

Exercises

  1. dd < /dev/sda1 | tee sda1.img | sha1sum > sda1.sha1
  2. find /etc -type f -print0 | tar -cJf /src/backup/etc.tar.xz --null -T -
    1. cat etc.tar.gz | ssh user@storage "cat > /src/backup.tar.gz"

103.5.1 create, monitor & kill processes

  • jobs -l: also display process ID
  • jobs -r: list only running processes
  • %str jobs whose command line starts with str
  • %?str jobs whose command line contains str
  • %% or %+ the job that was last started in bg
  • the default way for detaching processes seems to be `nohup ping localhost

    /path/to/log.file`

  • pgrep NAME find PID of program NAME
  • ps U User show only processes of User

103.5.2 terminal muxes, ...

In electronics a multiplexer or (mux) is a device that allows connecting multiple inputs to a single output.

screen

  • created in 1987!!!!
  • Prefix Ctrl-a
  • create new window Ctrl-a w
  • list all windows Ctrl-a "
  • window switching: Ctrl-a NUMBER or Ctrl-a n/p
  • change window title: Ctrl-a A or directly create a named window using screen -t NAME
  • split region Ctrl-a S or Ctrl-a |
  • move to region Ctrl-a TAB / Shift-TAB
  • kill current region Ctrl-a X
  • list sessions screen -list / -ls
  • start new sesh screen -S "sesh-name"
  • kill a sesh screen -S PID / NAME -X quit
  • detach a sesh Ctrl-a d
  • connect back to sesh if there is only one: screen -r else screen -r PID/NAME
  • other cmdline options for session mgmt:
    • -d -r re-attach and detach it first if necessary
    • -d -R same but even create the sesh if it does not exist
    • -d -m start screen detached. useful in scripts
  • scrollback mode: Ctrl-a [

tmux

  • create a new named sesh with named window in one push: tmux new -s "Sesh" -n "Sesh_Win"

103.5.6 processes, scheduler, nice

  • preemptive = unterbrechbar in german, meaning a preemptive multi-processing OS (like Linux) is such a OS that implements functionality that allows process of higher priority to interrupt execution of lower prio processes.
  • 2 different predicates determining scheduling for a process:
    1. scheduling policy
      • real-time and
      • normal
    2. scheduling priority
  • real-time processes have lowest priority numbers ranging from 0-99 (or the like). This value is never changed, that's why it is called static priority
  • normal processes have a so called dynamic prio which can be adjusted by the niceness
  • for running processes using renice
  • for new ones using nice
  • easy list your processes with prios: ps al
  • renice example sudo renice -5 PID
  • there is also schedtool. f.ex. you can set any process prio to real-time using schedtool -R -p 90 PID
  • ps sorting by cpu usage: ps al --sort=pcpu

103.7 regex, sed

  • brackets:
    • {i} last atom must appear exactly i times
    • {i,} at least i times
    • {i,j} at i times at most j times

Another nice once

<html>
<head>
<title>News Site</title>
</head>
<body>
<h1>Headline</h1>
<p>Information of interest.</p>
</body>
</html>

how to display on the body tag and its content using sed addresses?

cat file.html | sed -n '/<body>/,/<\/body>/p'!

Aaaand another nice one...

take this vpn cfg file:

client
dev tun
remote 192.168.1.155 1194
<ca>
ca.crt
</ca>
<cert>
client.crt
</cert>
<key>
client.key
</key>

assume the keys are saved in the corresponding files and you want to substitute them in here:

sed -r -E 's/(^[^.]*)\.(crt|key)$/cat 1円.2円/e' < client.template > client.ovpn

Major Learnings here:

  • with -e you can run commands on patterns!

Exercises

  1. what extended regex would match any email adress like info@example.org?

    echo "info@exmaple.org" | sed -E 's/\S+@\S+\.\S+//g'

  2. ipv4 adresses

    echo "192.168.6.12" | sed -E 's/[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+//'

  3. discard all comments

    head -n 30 < /etc/services | grep -v -E "^#.*"

  4. list .org and .com domains

    grep -E '.*\.org*|.*\.org/|.*\.com$|.*\.com/' < domain.txt

= The Cmd List =

  • sha256sum bla.txt > sha256.txt and sha256sum -c sha256.txt will check the hash of bla.txt against that in sha256.txt
  • od -x <file> is a simple hex-viewer
  • sed -n /pattern/p < file like grep
  • sed -n /pattern/d < file like grep -v
  • there is also the split cmd for splitting files into pieces like split -l 2 FILE PREFIX where PREFIX of the partitial files after split.
  • tr -s squeezes a multiple number of whitespaces into one. very useful!!!
  • using tr and cut multi field to parse ls -l output to only get username and filename: ls -l /etc | tr -s ' ' | cut -d ' ' -f3,9
  • mv -i like rm -i prompts you before overwriting anything
  • sudo find /var -size +2G find files bigger then 2G. other size params: -size 100c exactly 100 bytes, -size +100k bigger then 100kb, size -20M smaller than 20M
  • find . -name "*.conf" -exec chmod 644 '{}' \;
  • find . -type f -exec grep "lpi" '{}' \; -print
  • find . -name "bla" -delete yep, delete.
  • find . -perm /220 find file writable by either owner or group... more interestingly: 022
  • weird one finding all files in current dir which do not have a standard extension like .c or .txt: find . -type f -regextype egrep -not -rege ".*\.[[:alnum:]]+"
  • tar -cvf moep.tar stuff creates tar archive from content of dir stuff
  • tar -xvf moep.tar or tar -xvf moep.tar -C /tmp unpack (to dir /tmp)
  • tar -cvzf moep.tar.gz stuff gzip cvjf bzip2
  • ls | cpio -o > moep.cpio creates an cpio archive
  • cpio -id < moep.cpio extract
  • xargs: the files / args read from stdin can be assigned a variable name (PATH in this example) xargs -0 -I PATH mv PATH ./
  • find /etc -type f -print0 | tar -cJf /src/backup/etc.tar.xz --null -T - avoid the spaces-in-paths-problem agai n
  • grep also has null-termination option find . -print0 | grep -z expression
  • tmux new -s "Sesh" -n "Sesh_Win"
  • cat file.html | sed -n '/<body>/,/<\/body>/p' prints only the body tags and its content -> adresses can also be regex!