Avoid shell globbing enclose in single quotes: '*', '?' Assign shell variables with '=', do not include spaces. Variables can contain spaces if escaped with '\' STUFF=blah MORESTUFF=blah\ blah echo $STUFF $MORESTUFF PATH=dir:$PATH Assign environment variables with export so they are available to child processes STUFF=blah export STUFF Shell redirection. '>' To file '>>' Append to file '|' Pipe to next command '2>' Redirect error stream to file '> filename 2>&1' Redirect both standard output and error to file 'filename' '<' Redirect from file Run in background with '&', Use 'nohup' To run while logged out. Use 'fg to bring it back. List tasks with 'jobs'. 'Ctrl+Z' to return to background. gunzip file.gz & nohup gunzip file.gz Usernames are stored in '/etc/passwd'. Groups in '/etc/group' Add a scheduled task with 'crontab /file-to-add', Stored in /var/spool/cron/crontabs, list with '-l', remove with '-r', '-e' to install and run. alternatively use a systemd timer (timer/service pair) unit. 15 09 * * * /home/david/bin/spmake - everyday at 3:09 pm 15 09 15,24 * * /home/david/bin/spmake - On the 15th and 24th every month at 3:09 pm Schedule one To load virtual console press CTRL+ALT+'Function key', ALT+'Function key' to return to graphics mode. sudo 'chvt' 'console number' To change console. Partitions can have 4 primary partitions, 4+ extended partitions must be used to get logical partitions. Mount disks at boot time with /etc/fstab. Mount entries not marked with 'noauto' in fstab with mount -a. 'defaults' For no special options, 'user' To allow access to limited user accounts. Create initial RAM file system with mkinitramfs or dracut Single user mode with '-s' in bootloader. Systemd calls it rescue.target To edit systemd configuration edit /etc/systemd/system avoid /lib/systemd/system or /usr/lib/systemd/system. To add units, create unit file in /etc/systemd/sytem. Example test1.target: [Unit] Description=test 1 Wants=test0.target Type=simple #Process is main service process 'forking' Process starts another and then terminates. systemctl start test1.target - Start unit 'test1.target', 'stop' To stop systemctl enable 'unit' - Enable on startup, runs [Install] section, 'disable' To stop systemctl -p UnitPath show - Show system configuration path systemctl list-units - Show active units systemctl status 'unit'.service - (systemctl status sshd.service) systemctl reload 'unit' - Reloads just the configuration for 'unit' systemctl daemon-reload- Reload configuration for all units systemctl list-jobs - List running jobs, usually most are completed after boot. echo: Prints line to console, file or stream echo Hello there. echo $PATH echo '$PATH' cat: Outputs the contents of one or more files (concatenates) cat file1 file2 file3 ls: List contents of directory. -F File type information, -l Detailed information(long), -a Show hidden files ls -f . ls -l ~/Nextcloud/Linux grep: Prints lines from file or stream that match an expression. -i Case insensitive, -v Invert search, -E Regex grep root /etc/passwd cat /etc/passwd | grep david cp: Copy file. -r Recursive copy, -s Creates symbolic link cp file1 file2 file3 ~/Documents cp -r project-directory ~/Projects mv: Moves and can rename files mv oldfilename newfilename mkdir: Creates directory, -p recursively creates parent directories mkdir -p ~/projects/new-project/important-project-files/logs less: Displays large files one page at a time. Space bar moves forward 'b' moves back, 'q' quits, '/word' searches forward, '?word' searches back, 'n' continues searching, '+F' to follow document as it updates in real time. head -n 300 /dev/random | less pwd: Outputs name of current working directory. -P Prints without symbolic links pwd diff: Shows difference between two files. -u To output data to second program diff file1 file2 file: Guess file format file unknown-file head, tail: Shows the first or last 10 lines of a file. -n [num] Output 'num' lines, -n [+num] Print lines starting at line 'num', '-f' to follow updates tail -n +5 ~/.bash_history head -n 20 ~/.bash_history sort: Sorts in alphanumeric order. -n If lines in file start with numbers to sort numerically, -r Reverses order sort ~/.bash_history man: Opens the manual page of a command. -k 'keyword' searches for a command that contains that word in its manual man ls man -k filesystem info: Like man but for Gnu info man ps: List processes. 'x' Show all owned running processes, 'ax' Show system processes too, 'u' Show detailed information, 'w' Show full command lines ps axw kill: Terminate process with matching pid. '-STOP' Freeze process, '-CONT' Resume frozen process, '-KILL' Force stop a process kill -STOP 988800 chmod: Set permissions. Common changes: '644' user rw group & other r, '600' user rw group other none, '755' user rwex group other rex, '711' user rwex group other ex, '700' user rwex group other none. Directories should have execute permissions to access files chmod 644 file chmod g+r file chmod go+w file chown: Set file owner chown -R someuser:somegroup *.pdf ln: Create symbolic link. '-s' Create soft link ln -s target linkname gzip: Gnu Zip. 'gunzip' Extract zip file, 'gzip' Compress single file, '-d' Decompress, '-c' Redirects to stdout gzip file tar: Create tar archive that can contain multiple files. 'c' Create mode, 'v' Verbose, 'f' File option, '-' To output to stdout, 'x' to extract, 't' List filenames in table of contents, 'p' Preserve permissions of archive files, 'z' Unzips tar cvf archive-name input-file1 input-file2 tar xvf archive-name.tar tar ztvf file.tar.gz tar xf archive.tar -C /target/directory journalctl SYSLOG_IDENTIFIER=sudo: Prints log of sudoers actions journalctl: Prints log messages. '-k' Prints kernel messages, same as dmesg, less pretty but root not needed, '_PID=' To look for a specific process, '-S' Time eg. 4h, 06:00:00, 2020-01-14, '2020-01-14 14:30:00', '-u' Filter by unit eg '-u cron.service', '-F' List a values matching field, '-N', List all available fields, '-g' Filter by text with grep, '-b' From start of current boot add offset with -1 to get previous boot, etc, '-r' Reverse order, '--list-boots' Show boot ID list, '-p' Filter by severity 0 most important to 7 least, '-f' Follow mode, updates as messages appear journalctl -F _SYSTEMD_UNIT journalctl -u cron dd: Reads data from input stream. 'if=' Input file, 'of=' Output file, 'bs=' Block size, 'count=' Number of blocks, 'ibs=,obs=' Input/Output block size, 'skip=' Number of blocks to skip before reading dd if=/dev/zero of=new_file bs=1024 count=1 sudo dd if=rootfs.ext2 of=/dev/sda bs=1024 status=progress mknod: Creates device using device name and major and minor numbers mknod /dev/sda1 b 8 1 udevadm: Reload udevd rules, trigger events and monitor them. udevadm info --query=all --name=/dev/sda udevadm monitor --property parted: Edit partitions. '-l' List Partitions parted mkfs: Creates filesystems. '-t' File system type mkfs -t ext4 /dev/sdf2 mount: Lists mounted devices and mounts them. '-t' Type (usually optional), 'UUID=' Mount with UUID instead, Detach with umount 'mount point', '-o' Long format options mount -t ext4 /dev/sda3 /home/storage-drive umount /home/storage-drive mount -t vfat /dev/sde1 /dos -o ro,uid=1000 mount -n -o remount / blkid: List block device UUIDs blkid fdisk: Interactive partition editor. 'fdisk /dev/sdd' 'p' (print current table) 'd' (delete existing partition) 'n' (create new partition) 'p' (create primary partition) '1' (partition number) '2048' (first sector) '+200M' (create 200mb partition) 'p' (print changes) 'w' (write changes) 'q' (quit) sync: Syncs file system cache to all devices sync df: Lists file system information. '-h' Human readable sizes df df /home/david du: Disc usage of every directory. '-s' Summary mode grand total, '-s *' Evaluates all files and directories du -s ~/ du ~/ | sort -n | tail fsck: Checks for errors on an UNMOUNTED file system. '-p' Fixes ordinary problems. fsck /dev/sda2 free: Shows system memory and swap space. free ip: Shows network devices interfaces and tunnels. 'link' Lists interfaces, 'address' Shows network adresses ip link ip address lspci: Display pci bus information, '-nn' Show PCI vendor and device codes as both numbers and names,'-k' Show kernel drivers handling each device and also kernel modules capable of handling it. sudo lspci -nn sudo lspci -k ag: Search for strings in files like ack. '-c' Number of matches, '-f' follow sym links, '--hidden' Search hidden files, '-Q' Literal don't parse as regex ag restful ~/express mount -o subvolume=@ /dev/nvme1n1p2 /mnt arch-chroot /mnt reload udev rules: sudo udevadm control --reload-rules && sudo udevadm trigger root file system / bin/ dev/ etc/ usr/ home/ lib/ sbin/ tmp/ var/ | / \ bin/ man/ lib/ local/ sbin/ shar/ log/ tmp/ /bin: Basic Linux executable programs /dev: Contains device files /etc: Core system configuration files /home: Personal directories /lib: Library files (shared only) /proc: System statistics and running processes /run: Contains runtime data, process ids, socket files etc (var/run, in older systems) /sys: Device and system files like /proc /sbin: System executables, usually need to be run as root /tmp: Storage for temporary files, usually cleared on boot /usr: Where most of the Linux system is stored /var: Variable subdirectory records logs, cache user tracking, etc. var/tmp not cleared on boot /boot: Contains kernel bootloader files /media: Base attachment point for removable media /opt: Contains third party software, not usually used /vmlinuz or /boot/vmlinuz: Contains kernel /lib/modules: Contains loadable kernel modules that are loaded and unloaded while the sytem is running /usr/include: Header files /usr/local: Install admin software here /usr/man: Contains manual pages /usr/share: Contains auxiliary files