Learning Linux I: Basics Walkthrough

April 14, 2023
Documenting my journey with linux and devops

Linux KB #1 - Basics

find help

man
man -k w/ grep for relavant man kind (1-9)
tldr

fs

man heir (fs heir)

ln - symbolic/ hard links every file has an inode (need to check with manw) symbolic/symlink - plain shortcut used as alias (e.g. /bin -> /usr/bin) hardlink - actual ref copy of same file (points to same inode)

find (just tldr it) -exec iterator per result can use multiple execs xargs to pipe result

tar/ zip - archive and compression

working with textfiles

vimtutor - vim learning utility great for learning vim
less/more - file pager, use less, more is defunced
tail/head -# - read last/first # lines of text
cat/tac - cat and resverse cat
grep - find text using regex
cut - -d for delimiter; -f - field (slice number X)
sort - sorts by characters, -n for numeric sort
tr - translates char sets (used to lower/upper case ) tr from to
awk - very powerful programing language focused on string manipulation
sed - stream editor for string manipulation on iterables
diff - show diff between two files

RegEx

root

bash

shortcuts

ctr-l - clear screen ctr-u - clear current command line ctr-a - move to start of line ctr-e - move to end of line ctr-c - SIGINT current process ctr-d - SIGKILL current process

redirection and pipe

<   - stdin
>   - stdout
2>  - stderr
&>  - stdout + strerr
>>  - stdout append
|   - pipe output 

history

history -c clear -w write-to -d delete specific line Ctr-r reverse-i-search

variables & configurations

/etc/profile is executed while users login (!) /etc/profile.d is used as a snapin dir that contains additional configs (!) ~/.bash_profile can be used as user-specific version of profile.d (!) ~/.bash_logout is run when user logs out (can be used for cleanup scripts)

/etc/bashrc runs everytime a new sub shell is initiated (!) ~/.bashrc is a user-specific version of /etc/bashrc

users, groups and file ownership

PREMISSIONS | LNK |   OWNR       |  GRP  | SIZE |      DT     | NAME   
-rw-rw-r--    1      dani          dani      0    Apr 14 09:36 test

id - show user information (uid, gid groups)
getent - -”- w/ passwd | group
useradd - create new user (in ubuntu add -m tp add home dir for the new user)
usermod - modify user -aG <group> <user> to add user go group (as secondary group) -g <group> <name> (as primary group)
userdel - deletes user

groupadd - create a new group
groupmod - modify group
groupdel - deletes a group

vipw - edit user info with default text editor
vigr - edit group info with default text editor

passwd - manage and change password
chage - passwd related properties settings
chpasswd - can be used to pipeline new crediantials to change password without prompt (for scripting)

loginctl - systemd login manager, used to manage login sessions who - show who is logged and some related data
w - show who is logged and what they are doing

chown - change owner (user)
chgrp - change owner (group)
chmod - change premissions; 2 modes abosulte & relative overrides the need for the mentioned above

advanced premissions - WIP

umask - provides a value to subtract from the current premissions

storage managment essentials

/dev/sd[a,b,c..] SCSI hard disks
/dev/vd[a,b,c..] KVM hard disks
/dev/nvme0n - nvme hard disks
/dev/sr - optical drive

lsblk - list block devices
fdisk - format disk, used to create MBR disk partitions
gdisk - format disk util, used to create GPT partitions

mkfs.<fs> <part> - create a file system of fs type (mkfs.ext4) on top of the partition

mount - mounts a device mount /dev/sdb1 <target-location> unmount - unmounts a device df -h - presents mounted devices, including available disk space findmnt - shows all mounts nicely

networking

ifconfig - is deprecated on SysV unix, only use with BSD systems (MacOS)
ip - the right way to manage networks

BiosDevName

Biosdevname naming convensions for naming network devices, generated by systemd-udevd 
* em<port-num> - Ethernet Motherbord Portnumber
* p<port>p<slot> - PCI, PCI port
* eno123 - EtherNet Onboard
* if no sufficient info on the driver, generic eth<num> is used 

hostnamectl - get/set hostname

ping - verify host reachability
ss - utility to investigate sockets (ports)
dig - DNS lookup utility
nmap - powerful tool for network analysis
netstat - depricated; use ss
nslookup - deprecated; use dig

systemd

systemclt - controls systemd and service manager

ssh

ssh - secure shell
scp - file transfer via ssh
ssh-keygen - generate secure keys
ssh-copy-id - copy key to manged machine
ssh-agent - used to cache catchphrase answers for ssh connections
ssh-add - used to add catchephrase to ssh-agent

process managment

top - dynamic real-time information about running processes
ps - information about running processes
jobs - status of jobs in the current session
fg - run job in foreground
bg - resumes job that have been suspanded (e.g. Ctr + z) keeps them running in the background
nice - run process with custom priority
renice - alter priority of a running process
kill - kills a process by pid
killall - kills all processes with same name

task scheduling

cron - classic scheduler for reoccuring tasks
* uses the crond daemon
* use crontab -e to edit tasks
at - for tasks that need to run once only
* uses the atd daemon
* uses at to schedule the tasks

logs

journalctl - query systemd logs
rsyslogd - modern implemnetation of the old logger Syslog
logger - write to syslog