| lpic-101_notes.html | progress.. | |
| lpic-101_notes.org | moep | |
| README.md | okay that's about it | |
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)
-
lspci
-
Output of a simple
lspci00: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
-
-
lsusb
a simple
lsusblists 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 hubthe
lspcicounterpart forlsusbfor 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 -tto 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, 5000MIn the
Driverfield we can find the associated kernel module for each dev! It is also possible to query devices usinglsusb -s Bus.Port:Dev, very similarly tolspci. -
/procvs./sys/sysmore hardware related stuff/procalso other kernel structures like process info etc.
Exercises
nothing of great interest here
Key Takeaways for me
lsusb -tis very handy for indentifying kernel modules associated with usb deviceslspci -s 00:00.0 -kor-valso lists the kernel module use for a single dev- to achieve the same with
lspcione has to uselspci -v <address>whereaddressis retrieved from a call tolspci lsmodshows all currently loaded moduleslsmod | grep -i snd_hda_intellists all modules usingsnd_hda_intelmodulemodprobe -r <module_name>unload a module (that is currently not being used by any process or module)modprobe <module_name>load a modulemodinfoget all info about a modulemodinfo -pget 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
-
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
-
The Bootloader
- BIOS-systems: `Shift`-key brings up grub menu. UEFI: `Esc`
- Some kernel boot params:
mem: e.g.mem=512Mlimit amount of RAM availablemaxcpus: limit amount of CPUs (used in VMs a lot)quiet: hide boot msgsvga: e.g.vga=askshows list of available video modesroot: e.g.root=/dev/sdaset root partitionrootflags: mount options for root partitionro/rw: initial mount root fs ro/rw
- add kernel params to
/etc/default/grub'sGRUB_DEFAULT_LINUXentry && rungrub-mkconfig -o /boot/grub/grub.cfg - kernel params used to boot the current system are available at
run-time under
/proc/cmdline!!!
-
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
-
Initialization Inspection
- systemd -> there will also be
journalctl journalctl --list-bootsjournalctl -b -1last boots logs
- systemd -> there will also be
Key Takeaways for me
journalctl --list-bootslists available logs from past bootsjournalctl -b -1last boots logsjournalctl -D /path/to/other/journal/diropen journalctl for different then standard dirdmesg -Hfor 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
-
SysVinit
-
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
-
/etc/inittabinitlooks up what to do in/etc/inittab.initcan also get runvlevel info via kernel param.Syntax of
/etc/inittab:id:runlevels:action:processthe
actionfield tellsinitwhat to do with the command, f.ex:boot: process executed during system initializationwait: 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 qshould be run for reloading. - with
runlevelyou get the current runlevel. - This is all obsolete i'd say
-
-
systemd
- services = units in systemd speech
- a unit consists of a name, a type and a configuration file
-
7 distinct types of units
servicemost common. can be initiated, interrupted and reloadedsocketcan be any socket. all socket units have corresponding service unit loaded when the socket receives a requestdevicea device will only be taken as a systemd unit if a udev rule for this purpose exists.mountmount point def in fsautomounttargeta grouping of other units manages as a single unitsnapshotsaved state of the systemd manager
-
typical commands
systemctl...+status...is-active,enable,disable,is-enabled -
more commands
systemctl isolate multi-user.targetmanually alternates to this targetsystemctl set-default multi-user.targetchanges the link/etc/systemd/system/default.targetpoints to. usuallhygraphical.targetsystemctl get-defaultShow default targetsystemctl list-units[-files] --type=targetyep
-
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
timerandslice systemctl isolate multi-user.targetmanually alternates to this targetsystemctl set-default multi-user.targetchanges the link/etc/systemd/system/default.targetpoints to. usuallhygraphical.targetsystemctl get-defaultShow default targetsystemctl list-units[-files] --type=targetyep
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
-
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.efiorgrubx64.efifrom the ESP (/boot/EFI;)
-
/boot-
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.lstDEPRECATED!!! only grub legacy!/boot/grub/grub.cfgis the GRUB2 config file!
- Kernel config file
-
-
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
- check for boot partition on system using
-
configuring grub2
/boot/grub/grub.cfgis automatically generated- edit
/etc/default/grubinstead and then runupdate-grub - options in
/etc/default/grubGRUB_DEFAULTthe default menu entry to boot, either a number0,1,..or name likedebian, orsavedGRUB_SAVEDEFAULTif set totruethe default boot option will always be the last one selectedGRUB_TIMEOUT:0boot immediately,-1wait until user selects sthGRUB_CMDLINE_LINUXkernel params that will be added to every kernelGRUB_CMDLINE_LINUX_DEFAULTby default always a normal and a recovery menu entry are generated. this params only go to default entryGRUB_ENABLE_CRYPTODISKcheck for encripted disks & make booting them work
-
managing menu entries
-
update-grubscans 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 UUUUIIIIDDDinstead ofset root.. -
find UUID by
ls -l /dev/disk/by-uuid
-
-
the grub2 shell
- press
cto 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/sda1initrd /initrd.imgboot
so in principle enter the same stuff like in a menuentry.
- press
-
boot from rescue shell
set prefix=(hd0,msdos1)/boot/grubinsmod normalinsmod linux- then proceed like in the normal shell
Exercises
Key Takeaways for me
- press
cto 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/sda1initrd /initrd.imgboot
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 ldconfigmust be run every time conf-files change- use
LD_LIBRARY_PATHenv var for temporarily adding libs ldd!
102.4 Use of debian pkg manager
Key Takeaways for me
dpkg -I package.debfor inspecting pkgs seems quite nicedpkg -r / -Pfor removing / purging pkgsdpkg --get-selectionsget list of installed pkgs on systemdpkg -L unrarget list of files installed by pkg unrardpkg-query -S /usr/bin/unrar-nonfreefind out which pkg owns a specific file on systemdpkg-reconfigureruns the post-install configuration step again- when installing with Apt = Advanced Package Tool deb-files are
downloaded to
/var/cache/apt/archivesto clean that dir from time to time useapt clean. apt-cache search / showare the same asapt search / show/etc/sources.list...apt-file search libSDL2.sodoes the same thing likedpkg-querybut also in uninstalled pkgs.
102.5 RPM package manager
Key Takeaways for me
rpm -i PKGNAME.rpminstall pkg- use
rpm -ivh PKGNAME.rpmfor progress bar and verbosity rpm -U PKGNAMEupgrade pkgrpm -eerase aka remove a pkgrpm -qa"query all" lists all pkg installed on your systemrpm -qi pkg"query info" about a pkgrpm -ql unziplist files installed by pkg- do the same as the above two commands on a rpm-file:
rpm -qip pkg.rpmandrpm -qlp pkg.rpm dnf list --installedlist installed pkgs on systemdnf repolist (--enabled)list available (enabled) reposdnf config-manager --add-repo URLadd a repodnf 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
-
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:
virtioon KVM
-
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
- networks and VMs and everything else is saved in XML files under
-
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 --ensurechecks if the current system has an IDdbus-uuidgen --getget the ID which is located at/var/lib/dbus/machine-idand 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.txtwill 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
-
which users have access to bash shell?
for example:
$ cat passwd | grep bash | cut -d: -f1 -
List all users in group 1000 with sed
-
List all users of gid 1000 with their full name
sed -n 's/^\(.\+\):.\+:.\+:1000:\([A-Za-z ]\+\).\+$/2円/p' < passwdusing
sedandcut:sed -n 's/^\(.\+\):.\+:.\+:1000:\([^:]\+\):.\+$/2円/p' < passwd | cut -d, -f1or another one
sed -n '/:[[:digit:]]\+:1000/p' < passwd | cut -d: -f5 | cut -d, -f1 -
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 -
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:
cspecial file-regular fileddir
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:
fregular fileddirlsymbolic link
-inamelike but case-insensitive-notreturn results that do not match case-maxdepth Nmaximum dir depth-mtime 7modification time during the last 7 dayssudo find /var -size +2Gfind 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/stdinand/dev/stderr - aha! major learning! the syntax in
2>&1has to be like this because prefixing a number with an ampersand like in&1denotes 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 noclobberredirecting 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
xargsis 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
(
PATHin this example)xargs -0 -I PATH mv PATH ./
Exercises
dd < /dev/sda1 | tee sda1.img | sha1sum > sda1.sha1find /etc -type f -print0 | tar -cJf /src/backup/etc.tar.xz --null -T -cat etc.tar.gz | ssh user@storage "cat > /src/backup.tar.gz"
103.5.1 create, monitor & kill processes
jobs -l: also display process IDjobs -r: list only running processes%strjobs whose command line starts withstr%?strjobs whose command line containsstr%%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 NAMEfind PID of program NAMEps U Usershow 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 NUMBERorCtrl-a n/p - change window title:
Ctrl-a Aor directly create a named window usingscreen -t NAME - split region
Ctrl-a SorCtrl-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 -relsescreen -r PID/NAME - other cmdline options for session mgmt:
-d -rre-attach and detach it first if necessary-d -Rsame but even create the sesh if it does not exist-d -mstart 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:
- scheduling policy
- real-time and
- normal
- scheduling priority
- scheduling policy
- 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 usingschedtool -R -p 90 PID pssorting 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
-eyou can run commands on patterns!
Exercises
-
what extended regex would match any email adress like
info@example.org?echo "info@exmaple.org" | sed -E 's/\S+@\S+\.\S+//g' -
ipv4 adresses
echo "192.168.6.12" | sed -E 's/[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+//' -
discard all comments
head -n 30 < /etc/services | grep -v -E "^#.*" -
list .org and .com domains
grep -E '.*\.org*|.*\.org/|.*\.com$|.*\.com/' < domain.txt
= The Cmd List =
sha256sum bla.txt > sha256.txtandsha256sum -c sha256.txtwill check the hash ofbla.txtagainst that insha256.txtod -x <file>is a simple hex-viewersed -n /pattern/p < filelike grepsed -n /pattern/d < filelike grep -v- there is also the
splitcmd for splitting files into pieces likesplit -l 2 FILE PREFIXwherePREFIXof the partitial files after split. tr -ssqueezes a multiple number of whitespaces into one. very useful!!!- using
trand cut multi field to parsels -loutput to only get username and filename:ls -l /etc | tr -s ' ' | cut -d ' ' -f3,9 mv -ilikerm -iprompts you before overwriting anythingsudo find /var -size +2Gfind files bigger then 2G. other size params:-size 100cexactly 100 bytes,-size +100kbigger then 100kb,size -20Msmaller than 20Mfind . -name "*.conf" -exec chmod 644 '{}' \;find . -type f -exec grep "lpi" '{}' \; -printfind . -name "bla" -deleteyep, delete.find . -perm /220find 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
.cor.txt:find . -type f -regextype egrep -not -rege ".*\.[[:alnum:]]+" tar -cvf moep.tar stuffcreates tar archive from content of dir stufftar -xvf moep.tarortar -xvf moep.tar -C /tmpunpack (to dir /tmp)tar -cvzf moep.tar.gz stuffgzipcvjfbzip2ls | cpio -o > moep.cpiocreates an cpio archivecpio -id < moep.cpioextractxargs: the files / args read from stdin can be assigned a variable name (PATHin 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!