systemd

Cheatsheet ========================================== ========================================== INFORMATION LOGS ========================================== ========================================== systemctl journalctl list-dependencies -u <name> by service list-sockets -f follow live log list-jobs -k kernel messages list-unit-files -k kernel messages list-units -r reverse (newest first) get-default -o json format output --type=service --all -b -1 from previous boot -n 10 limit output lines (tail) ========================================== -S,--since e.g "2012-10-30 18:17:16" SERVICES -U,--until e.g. "10 min ago" ========================================== systemctl ========================================== stop <name> SYSTEM STATES start <name> ========================================== restart <name> reload <name> systemctl status <name> reboot reboot.target enable <name> poweroff poweroff.target disable <name> emergency emergency.target show <name> default default.target -H <host> status network

May 20, 2017 · 1 min

Red Hat Certified System Administrator 8 (RHCSA)

I’m a software engineer not a sysadmin. In fact I know I’m a bad one. The RHCSA is a rote, mechanical process. It did force me to discover discover several gaps in my GNU/Linux knowledge so overall happy about that. Essential Tools Documentation man /usr/share/doc RPM bundled documentation General Searching Techniques Shell history Globbing I/O Redirection and Pipes Essential File Management Linux file system layout Finding Files locate find Archiving and compression with tar Hard and Soft Links Working with text Regular expressions grep sed and awk Connecting a Linux host Consoles Terminals and TTYs Switch Users (su) sudo SSH Managing users and groups Creating users User properties User configuration files Creating and managing groups Managing password properties Managing Permissions Changing file ownership Managing basic permissions Understanding umask (user mask) Special permissions suid sgid Sticky bit Understanding ACLs Configuring Networking Network device naming Managing runtime network configuration with ip Storing network configuration persistently nmcli Routing and DNS Managing Processes Shell jobs ps Memory usage CPU load System activity with top Sending signals to processes Priority and niceness tuned profiles Managing Software RPM and yum rpm queries yum Groups Repositories Modules and Application Streams Red Hat Subscription Manager Systemd Scheduling Tasks cron at systemd Timers tmpfiles.d Logging Rsyslog Systemd Journal Logrotate Managing Storage Disk layout Creating partitions GPT partitions with parted MBR partitions with fdisk File System Choices XFS Ext4 Mounting Persistent block device naming systemd mounts Swap Advanced Storage LVM Stratis VDO LUKS Advanced tasks Kernel management Boot procedure GRUB Systemd targets Essential troubleshooting Changing root password Managing network services SSH httpd (apache) SELinux Context Labels Booleans File context labels SELinux logs SELinux troubleshooting Firewalling with firewalld Automating installs Time services Remote file systems NFS CIFS with Samba Automount Containers Autostarting non-root containers with systemd user units Dont forget list Exam shakedown Linux Gems Essential Tools Documentation The ability to understand a program using local documentation resources; man, info, /usr/share/doc, within the RPM package. ...

May 3, 2017 · 47 min

Computer Heros

Some heros in the world of computer science. Founding Fathers (pre 1960) George Boole (1815 - 1864) Boolean algegra. Papers The Mathematical Analysis of Logic (1847), and An Investigation of the Laws of Thought (1854). Friedrich Ludwig Gottlob Frege (1848 - 1925) Analytic philosophy. Developed modern logic in the Begriffsschrift and work in the foundations of mathematics. Books The Foundations of Arithmetic, On Sense and Reference and The Thought. Alan Turing (1912 - 1954) The father of theoretical computer science. Formalised the concepts of algorithm and computation through the notion of a Universal Machine (i.e Turing Machine) in his seminal paper On Computable Numbers, with an Application to the Entscheidungsproblem. ...

April 27, 2017 · 2 min

Tmux Quick Reference

Kudos to afair for putting together this neat Tmux Cheat Sheet, which I’m addicted to at the moment. ========================================== ========================================== TMUX COMMAND WINDOW (TAB) ========================================== ========================================== List tmux ls List ^b w New -s <session> Create ^b c Attach att -t <session> Rename ^b , <name> Rename rename-session -t <old> <new> Last ^b l (lower-L) Kill kill-session -t <session> Close ^b & ========================================== Goto # ^b <0-9> CONTROLS Next ^b n ========================================== Previous ^b p Choose ^b w <name> Detach ^b d List ^b = ========================================== Buffer ^b <PgUpDn> PANE (SPLIT WINDOW) Command ^b : <command> ========================================== Copy ^b [ ... <space> ... <enter> Show # ^b q Moving vim/emacs key bindings Split Horiz ^b " -------- Start <space> Split Vert ^b % | Copy <enter> Pane->Window ^b ! Paste ^b ] Kill ^b x ========================================== Reorganize ^b <space> SESSION (Set of Windows) Expand ^b <alt><arrow> ========================================== Resize ^b ^<arrow> Resize x n ^b <n> <arrow> New ^b :new ^b :new -s <name> Rename ^b $ Select ^b <arrow> List ^b s Previous ^b { Next ^b ( Next ^b } Previous ^b ) Switch ^b o other Swap ^b ^o Last ^b ;

April 17, 2017 · 1 min

DIY Computer Part 5 Machine Architecture

A continuation of my participation in the amazing Nand2Tetris course, by Noam Nisan and Shimon Schocken, now running on Coursera. Related posts: [DIY Computer Part 1 The NAND Gate]({% post_url 2016-03-06-diy-computer-nands %}) [DIY Computer Part 2 The ALU]({% post_url 2016-03-12-diy-computer-alu %}) [DIY Computer Part 3 Memory]({% post_url 2016-03-12-diy-computer-alu %}) [DIY Computer Part 4 Machine Language]({% post_url 2016-05-23-diy-computer-ml %}) Now armed with the necessary elementary logic gates and chips, are now ready to assemble a general purpose computer. Using a finite amount of hardware, it will be capable of performing practically an infinite number of tasks (e.g. games, word processing, networking). This remarkable flexibility, the fruit of the profound invention of several mathematicians in the 1930’s, is known as the stored program. ...

April 17, 2017 · 6 min

Nerd Gems 💎

This is a list of valuable (to me) developer resources that I’ve managed to stumble across (books, courses, friends and fellow programmers, hacker news, lobste.rs, university). Architecture AI and ML Books and Reading Lists C Compilers and Interpreters Cloud Containers Cheat sheets Databases Developer culture Diagramming dotfiles Git Golang gRPC Hardware Humanities Jobs Kubernetes Linux Message queues Mongo Monitoring Networking Open source Python Rust Security Shell systemd Text wrangling Talks Tasks Terminal Testing Text, Encoding and Serialization Vim Web Writing Architecture .NET Microservices: Architecture for Containerized .NET Applications a fantastic resource for working with the modern .NET stack (post 2022) Communicating Sequential Processes Tony Hoare’s seminal 1977 paper on concurrency and CSP Why Segment Went Back to a Monolith microservices come with serious tradeoffs All software sucks complexity is the bane of all software, simplicity is the most important quality Designing Actor-Based Software with Hugh McKee an approach to building scalable software systems Queueing: An interactive study of queueing strategies an interactive journey to understand common queueing strategies for handling HTTP requests. AI and ML Andrej Karpathy on The spelled-out intro to neural networks and backpropagation: building micrograd a 2.5 hour step-by-step spelled-out explanation of backpropagation and training of neural networks. It only assumes basic knowledge of Python and a vague recollection of calculus from high school. A Beginner’s Guide to Vector Embeddings Books and Reading Lists Arjan Codes Books learn-anything/books A Programmer’s Reading List: 100 Articles I Enjoyed 1-50 C Easy Makefile a Makefile boilerplate to hit the ground running Handmade Hero an educational series by Casey Muratori that teaches low-level game programming techniques by example Eskil Steenberg on How I program in C Compilers and Interpreters Crafting Interpreters by Robert Nystrom Ever wanted to make your own programming language or wondered how they are designed and built? If so, this book is for you. You should make a new programming language Cloud mcm Minimal Configuration Manager Packer a tool for building images for cloud platforms, virtual machines, containers and more from a single source configuration. CloudBoost a complete serverless platform for your app. The Google Cloud Developer’s Cheat Sheet every product in the Google Cloud family described in under 4 words Ask HN: Is Your Company Sticking to On-Premise Servers? Why? Using AWS CodeBuild to Execute Administrative Tasks What Is Amazon Resource Name (ARN)? more to the humble ARN than you think arn:partition:service:region:account-id:resource Containers Building Docker Images - Best Practices The Docker Handbook 25 Basic Docker Commands for Beginners Setting the Record Straight: containers vs. Zones vs. Jails vs. VMs Docker Security Best Practices tools and methods to help secure Docker Kubernetes Workshop tons of details for getting started 10 Most Common Mistakes When Using Kubernetes lens kube IDE kubeseal how to safely store secrets in git if you want to use them in k8s Container Technologies at Coinbase great history on how the industry got to containers, an why kubernetes isn’t used A Practical Introduction to Container Security Webtop full desktop environments in officially supported flavors accessible via any modern web browser Cheat sheets Linux Commands - A practical reference an amazing cheat sheet, quick reference The Ultimate List of SANS Cheat Sheets when it comes to quality cyber-security training and certs SANS is world leading. They have an amazing collection of thoughtful and useful cheat sheets from topics such as Writing Tips for IT Professionals, Windows to Unix Cheat Sheet, to using pieces of software such as nmap, netcat, burp. Its a treasure trove! Lenny Zeltser’s IT and Information Security Cheat Sheets speaking of thoughtful cheat sheets, lots of wisdom here Databases Things I Wished More Developers Knew About Databases SQL Coding Standards PostgreSQL Course: A Curious Moon learn PostgreSQL the way the pros do: on the job and under pressure. You’ll assume the role of interim DBA at aerospace startup Red:4, exploring data from the Cassini mission! Developer culture Eric S Raymond talking about The Cathedral and the Bazaar The Problem with Vibe Coding The Post-Developer Era Lessons Learned in 35 Years of Making Software What To Code inspiration and ideas Why the developers who use Rust love it so much Why we’re leaving the cloud You Are Not Google if you’re using a technology that originated at a large company, but your use case is very different, it’s unlikely that you arrived there deliberately; no, it’s more likely you got there through a ritualistic belief that imitating the giants would bring the same riches. GitLab’s Guide to All-Remote the remote manifesto, tips and tricks and remote resources Why we at $FAMOUS_COMPANY Switched to $HYPED_TECHNOLOGY Habbits of High-Functioning Software Teams characteristics and habits of the highest-performing dev teams A Taxonomy of Tech Debt Diagramming Excalidraw beautiful web based diagrams PlantText PlantUML (text) based diagram generator Taking ASCII Drawings Seriously: How Programmers Diagram Code dotfiles HexDSL LukeSmithxyz uoou Git Better Git configuration links and resources on configuring & using git Automate Repetitive Tasks with Custom git Commands how to write custom git commands Golang Everyday Golang LearnGo: A Large Collection of Go Examples, Exercises, and Quizzes Writing Go CLIs With Just Enough Architecture Getting Hands-On with io_uring from Go Diving Into Go by Building a CLI Application Immutability Patterns in Go Writing An Interpreter In Go gRPC gRPC - Best Practices Hardware Backblaze hard drive stats Build an 8-bit CPU by Ben Eater a programmable 8-bit computer from scratch on breadboards using only simple logic gates nand2tetris a distilled version of the book The Elements of Computing Systems, By Noam Nisan and Shimon Schocken (MIT Press), contains all the project materials and tools necessary for building a general-purpose computer system and a modern software hierarchy from the ground up Humanities The Chomsky List A definitive guide to Noam Chomsky: 10 books to get you started RATM reading list Jobs Inspired corp Kubernetes 7 Mind-Blowing Kubernetes Hacks The guide to kubectl I never had The Pros of On-Prem Kubernetes with Justin Garrison Languages Crafting Interpreters by Robert Nystrom Ever wanted to make your own programming language or wondered how they are designed and built? If so, this book is for you. Linux Linux Commands - A practical reference an amazing cheat sheet, quick reference 16 Linux server monitoring commands you really need to know Best 15 Unix Command Line Tools An In-Depth Guide to iptables covers pretty much every angle of iptables, from basic rules to NAT’ing to protocols and interfaces. mdadm Cheat Sheet practical commands when running software raid on Linux Async IO on Linux: select, poll, and epoll thorough write-up on ‘select’, ‘poll’ and ’epoll’ system calls, and how to measure them. The first 5 things to do when your Linux server keels over including hardware troubleshooting, checking the running state of applications How io_uring and eBPF Will Revolutionize Programming in Linux well explained history of Linux syscalls and their limitations, and how io_uring is a game changer by allowing async I/O via a pub/sub model bashtop gamified TUI resource monitor that shows usage and stats for processor, memory, disks, network and processes Time on Unix how time and localization works on Unix Tmux for mere mortals good defaults, modifying the keybindings to boost usability Tips for cleaning up a Linux server low hanging disk space fruit, like removing old kernels, pruning unused Docker space, clearing logs Shell productivity tips and tricks faster command line tips Message queues Postgres Message Queue - PGMQ lightweight message queue, like AWS SQS and RSMQ but on Postgres Mongo Quick reference cards Aggregation pipeline quick reference Monitoring Zabbix whatfiles logs the files programs CRUD, also traces new processes logtop reads stdin, can sort on any field and is updated in realtime Networking PacketLife Cheat Sheets The Packet Pioneer Chris Greer on TCP Fundamentals Part 1 TCP/IP Explained with Wireshark 59 Linux Networking commands and scripts the ultimate network tools goto list. Introduction to tcpdump and wireshark hping3 send arbitary TCP/IP packets to network hosts Setting up a Linux mail server linker∙d dynamic linker for microservices, taking care of the communication work needed to interact with distributed services, including routing, load balancing, and retrying. Manually Throttle the Bandwidth of a Linux Network Interface introduction to the tc tool for bandwidth shaping. connbeat agent that monitors TCP connection metadata and ships the data to Kafka or Elasticsearch, or an HTTP endpoint The Ultimate PCAP all protocols in a single PCAP What Every Developer Should Know About TCP SSH Tips & Tricks 2FA, securely forwarding agents, quitting from stuck sessions and using mosh or tmux High Availability Load Balancers with Maglev CloudFlare on their load balancing stack, BGP, Maglev connection scheduling, IPVS, UDP encapsulation for faster delivery Networking for Game Programmers: UDP vs TCP Open source Google Open Source 2000+ OSS projects managed by Google NSA on GitHub Python Interactive Python Type Challenges packse: Python packaging scenarios Python Design Patterns Inside the Python Virtual Machine Full Speed Python from Superior School of Technology of Setúbal Intermediate Python Ruff: Internals of a Rust-backed Python linter-formatter - Part 1 A Guide to Python’s Weak References Using weakref Module A Complete Guide to Pytest Fixtures Rust 100 Exercises To Learn Rust teaches Rust’s core concepts, one exercise at a time. You’ll learn about Rust’s syntax, its type system, its standard library, and its ecosystem. Security OST2.FYI OpenSecurityTraining2’s mission is to provide the world’s deepest and best cybersecurity training. That our classes are free is just a bonus! The Ultimate List of SANS Cheat Sheets when it comes to quality cyber-security training and certs SANS is world leading. They have an amazing collection of thoughtful and useful cheat sheets from topics such as Writing Tips for IT Professionals, Windows to Unix Cheat Sheet, to using pieces of software such as nmap, netcat, burb. Its a treasure trove! Lenny Zeltser’s IT and Information Security Cheat Sheets speaking of thoughtful cheat sheets, lots of wisdom here Linux reverse engineering 101 collection of resources for linux reverse engineering. Explain like I’m 5: Kerberos OAuth 2.0 Security Best Current Practices SSHHeatmap script that generates a heatmap of IP’s that made failed SSH login attempts using /var/log/auth.log psst Paper-based Secret Sharing Technique Shell Byobu multiplexer, enhanced profiles, convenient keybindings, configuration utilities, and toggle-able system status notifications for screen and tmux Makeself a self-extracting archiving tool for Unix systems, in 100% shell script 5 Types Of ZSH Aliases You Should Know alias suffixes & global aliases, plus other neat tricks Bash aliases you can’t live without systemd Why I Prefer systemd Timers Over Cron journal-triggerd runs trigger on systemd’s journal messages How to automatically execute shell script at startup boot on systemd Text wrangling CyberChef the ultimate open-source (by GCHQ) text wrangler you’ll ever need, life changing desed beautiful TUI that provides users with comfortable interface and practical debugger, used to step through complex sed scripts sed One Liners huge collection of useful sed examples xsv CLI for indexing, slicing, analyzing, splitting and joining CSV files Talks Rich Hickey on Simple Made Easy Mike Acton on Data-orientated Design Jonathan Blow on Programming Aesthetics learned from making independent games Eskil Steenberg on How I program in C Rich Hickey on Hammock Driven Development Brian Will on Why OOP is Bad Abner Coimbre on What Programming is Never About Scott Meyers on CPU Caches and Why You Care Jeff and Casey Show on The Evils of Non-native Programming Jeff and Casey’s Guide to Becoming a Bigger Programmer Hadi Hariri on The Silver Bullet Syndrome Bryan Cantrill on Fork Yeah! The Rise and Development if illumos Rob Pike on Concurrency Is Not Parallelism James Mickens on JavaScript Liz Rice on Containers From Scratch James Mickens on Why Do Keynote Speakers Keep Suggesting That Improving Security Is Possible? Tasks Learn Makefiles Abusing Makefiles for fun and profit Terminal Terminal Text Effects visual effects applied to text in the terminal Terminal Terminal Text Effects visual effects applied to text in the terminal Testing Smocker simple HTTP mock server, uses YAML to define mocks and responses MockServer for any system you integrate with via HTTP or HTTPS MockServer can be used as: a mock configured to return specific responses for different requests, a proxy recording and optionally modifying requests and responses or as both a proxy for some requests and a mock for other requests at the same time Text, Encoding and Serialization The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) Illustrated jq tutorial jq is a lightweight and flexible command-line JSON processor Cap’n Proto Google Protocol Buffers Vim A Flexible Minimalist Neovim for 2024 A Case for Using Neovim Without Plugins Web The Consise TypeScript Book HTML5 UP makes spiffy HTML5 site templates that are HTML5 + CSS3, customizable and 100% free under the Creative Commons How I built a modern website in 2021 Certbot automatically use Let’s Encrypt certificates Ask HN: Is There Still a Place for Native Desktop Apps? topngx parse and aggregrate statistics from NGINX access logs Writing Dungeons and Dragons taught me how to write alt text

April 2, 2017 · 11 min

Operational PGP

A practical guide about doing secure email the right way with PGP. I did not write this guide. Credits to the author grugq. Original source. In case this guide goes missing in the future, wanted to preserve it for my own future reference. Operational PGP This is a guide on how to email securely. There are many guides on how to install and use PGP to encrypt email. This is not one of them. This is a guide on secure communication using email with PGP encryption. If you are not familiar with PGP, please read another guide first. If you are comfortable using PGP to encrypt and decrypt emails, this guide will raise your security to the next level. ...

February 20, 2017 · 8 min

Linux cheatsheet

A survey of the standard and high quality programs that feature in most Unix based distributions, with the GNU variants being my favourite. The bash shell is a great way of interfacing and orchestrating these beautifully crafted programs. As a starting point, I’ve listed each program offered by the GNU Core Utilities and util-linux umbrella projects; considered the de facto standard on most distributions. Quick Reference General System Information Directory Navigation File Searching Archiving and Compression Networking Text Manipulation Set Operations Windows Networking Monitoring and Debugging Disk Space CD/DVD Locales Dates and Times Images Finding Documentation Manual Pages Appropriate Commands whatis GNU Info Entry /usr/share/doc Documentation RPM bundled documentation Examples grep cut sort tr wc tar rsync sed awk ssh (Secure Shell) wget BFL of Common Programs Resources Quick Reference General Command What is does apropos compress Show commands that relate to a keyword man -t ascii | ps2pdf - > ascii.pdf Make a PDF of a man page which command Full path of command time command Show execution time of a given command time cat Start stopwatch, ^d to stop cat file.txt | xclip -selection clipboard Copy to clipboard nohup ./script.sh & Keep program running after leaving SSH session (see bash post if input needed) timeout 20s ./script.sh Run script.sh for 20 seconds only while true; do timeout 30m ./script.sh; done Restart a program every 30 minutes System Information Command What is does uname -a Show kernel version and system architecture head -n1 /etc/issue Show name and version of distribution cat /proc/partitions Show all partitions registered on the system grep MemTotal /proc/meminfo Show RAM total seen by the system grep "model name" /proc/cpuinfo Show CPU(s) info lspci -tv Show PCI info lsusb -tv Show USB info mount | column -t List mounted filesystems on the system (and align output) grep -F capacity: /proc/acpi/battery/BAT0/info Show state of cells in laptop battery dmidecode -q | less Display SMBIOS/DMI information smartctl -A /dev/sda | grep Power_On_Hours How long has this disk (system) been powered on in total hdparm -i /dev/sda Show info about disk sda hdparm -tT /dev/sda Do a read speed test on disk sda badblocks -s /dev/sda Test for unreadable blocks on disk sda Directory Navigation Command What is does cd - Go previous directory cd Go home (cd dir123 && pwd) Jump into a directory, run a command there, and return to origin pushd . Put cwd on stack, so you can popd back to it File Searching Command What is does alias l='ls -l --color=auto' Quick listing ls -lrt List long by date ls -lS List long by size ls /usr/bin | pr -T9 -W$COLUMNS Print in 9 columns to width of terminal find -name '*.[ch] | xargs grep -E 'foo' Search for ‘foo’ in all .c and .h files in cwd and below find -type f -print0 | xargs -r0 grep -F 'example' Search all regular files for ’example’ find -maxdepth 1 -type f | xargs grep -F 'example' As above, but don’t recurse find -maxdepth 1 -type d | while read dir; do echo $dir; echo somecmd; done Wash each result over multiple commands find -type f ! -perm -444 Find files not readable by all find -type d ! -perm -111 Find dirs not accessable by all find . -size 30c By file size (30 bytes) find . -name "*.gz" -delete Delete all gz files locate -r 'file[^/]*\.txt Search cached index for names look <keyword> Search English dictionary with a given prefix keyword grep --color reference /usr/share/dict/words Highlight occurances of regex against English dictionary readlink -f file.txt Full path of file namei -l /bin/bash Drills through directories and links showing permission mask all the way down Archiving and Compression Command What is does gpg -c file Encrypt file gpg file.gpg Decrypt file tar -c dir/ | bzip2 > dir.tar.bz2 Make compressed archive of dir bzip2 -dc dir.tar.bz2 | tar -x Extract archive tar -c dir/ | gzip | gpg -c | ssh user@remote ‘dd of=dir.tar.gz.gpg’ Make encrypted archive of dir on remote machine find dir/ -name ‘*.txt’ | tar -c –files-from=- | bzip2 > dir_txt.tar.bz2 Make archive of subset of dir and below find dir/ -name ‘*.txt’ | xargs cp -a –target-directory=dir_txt/ –parents Make copy of subset of dir and below ( tar -c /dir/to/copy ) | ( cd /where/to/ && tar -x -p ) Copy (with permissions) copy/ dir to /where/to/ dir ( cd /dir/to/copy && tar -c . ) | ( cd /where/to/ && tar -x -p ) Copy (with permissions) contents of copy/ dir to /where/to/ ( tar -c /dir/to/copy ) | ssh -C user@remote ‘cd /where/to/ && tar -x -p’ Copy (with permissions) copy/ dir to remote:/where/to/ dir dd bs=1M if=/dev/sda | gzip | ssh user@remote ‘dd of=sda.gz’ Backup harddisk to remote machine Networking Command What is does ethtool eth0 Show status of ethernet interface eth0 ethtool --change eth0 autoneg off speed 100 duplex full Manually set ethernet interface speed iw dev wlan0 link Show link status of wireless interface wlan0 iw dev wlan0 set bitrates legacy-2.4 1 Manually set wireless interface speed iw dev wlan0 scan List wireless networks in range ip link show List network interfaces ip link set dev eth0 name wan Rename interface eth0 to wan ip link set dev eth0 up Bring interface eth0 up (or down) ip addr show List addresses for interfaces ip addr add 1.2.3.4/24 brd + dev eth0 Add (or del) ip and mask (255.255.255.0) ip route show List routing table ip route add default via 1.2.3.254 Set default gateway to 1.2.3.254 ss -tupl List internet services on a system ss -tup List active connections to/from system host bencode.net Lookup DNS ip address for name or vice versa hostname -i Lookup local ip address (equivalent to host hostname) whois bencode.net Lookup whois info for hostname or ip address mtr google.com Nice trace route Text Manipulation Command What is does sed 's/string1/string2/g' Replace string1 with string2 sed 's/\(.*\)1/\12/g' Modify anystring1 to anystring2 sed '/^ *#/d; /^ *$/d' Remove comments and blank lines sed ':a; /\\$/N; s/\\\n//; ta' Concatenate lines with trailing \ sed 's/[ \t]*$//' Remove trailing spaces from lines seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" Right align numbers seq 10 | sed p | paste - - Duplicate a column sed -n '1000{p;q}' Print 1000th line sed -n '10,20p;20q' Print lines 10 to 20 sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q' Extract title from HTML web page sed -i 42d ~/.ssh/known_hosts Delete a particular line sort -t. -k1,1n -k2,2n -k3,3n -k4,4n Sort IPV4 ip addresses echo 'Test' | tr '[:lower:]' '[:upper:]' Case conversion tr -dc '[:print:]' < /dev/urandom Filter non printable characters tr -s '[:blank:]' '\t' </proc/diskstats | cut -f4 cut fields separated by blanks history | wc -l Count lines seq 10 | paste -s -d ' ' Concatenate and separate line items to a single line sort -u file1 file2 Union of unsorted files sort file1 file2 | uniq -d Intersection of unsorted files sort file1 file1 file2 | uniq -u Difference of unsorted files sort file1 file2 | uniq -u Symmetric Difference of unsorted files join -t'\0' -a1 -a2 file1 file2 Union of sorted files join -t'\0' file1 file2 Intersection of sorted files join -t'\0' -v2 file1 file2 Difference of sorted files join -t'\0' -v1 -v2 file1 file2 Symmetric Difference of sorted files shuf file1 Randomise lines in a file comm file1 file2 Combine lines from two sorted files Set Operations Command What is does sort -u file1 file2 Union of unsorted files sort file1 file2 | uniq -d Intersection of unsorted files sort file1 file1 file2 | uniq -u Difference of unsorted files sort file1 file2 | uniq -u Symmetric Difference of unsorted files join -t'\0' -a1 -a2 file1 file2 Union of sorted files join -t'\0' file1 file2 Intersection of sorted files join -t'\0' -v2 file1 file2 Difference of sorted files join -t'\0' -v1 -v2 file1 file2 Symmetric Difference of sorted files Windows Networking Command What is does smbtree Find windows machines. See also findsmb nmblookup -A 1.2.3.4 Find the windows (netbios) name associated with ip address smbclient -L windows_box List shares on windows machine or samba server mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/share Mount a windows share echo 'message' | smbclient -M windows_box Send popup to windows machine Monitoring and Debugging Command What is does tail -f /var/log/messages Monitor messages in a log file strace -c ls >/dev/null Summarise/profile system calls made by command strace -f -e open ls >/dev/null List system calls made by command strace -f -e trace=write -e write=1,2 ls >/dev/null Monitor what’s written to stdout and stderr ltrace -f -e getenv ls >/dev/null List library calls made by command lsof -p $$ List paths that process id has open lsof ~ List processes that have specified path open tcpdump not port 22 Show network traffic except ssh. See also tcpdump_not_me ps -e -o pid,args --forest List processes in a hierarchy ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d' List processes by % cpu usage ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS List processes by mem (KB) usage. See also ps_mem.py ps -C firefox-bin -L -o pid,tid,pcpu,state List all threads for a particular process ps -p 1,$$ -o etime= List elapsed wall time for particular process IDs watch -n.1 pstree -Uacp $$ Display a changing process subtree last reboot Show system reboot history free -m Show amount of (remaining) RAM (-m displays in MB) watch -n.1 'cat /proc/interrupts' Watch changeable data continuously udevadm monitor Monitor udev events to help configure rules ulimit -Sv 1000 Limit memory usage for following commands to 1MiB fuser -k 8000/tcp Kill the program using port 8000 lsof -p 123,789 -u 1234,abe All files used by PID 123 or 789, or by user abe or UID 1234 kill -HUP $(lsof -t /home/foo/file) SIGHUP the processes using /home/foo/file cat /dev/urandom | base64 | pv -lbri2 > /dev/null Monitor progress of output Disk Space Command What is does ls -lSr Show files by size, biggest last du -s * | sort -k1,1rn | head Show top disk uses in current dir du -hs /home/* | sort -k1,1h Sort paths by easy to interpret disk usage df -h Show free space on mounted filesystems df -i Show free inodes on mounted filesystems fdisk -l Show disks partitions sizes and types (run as root) rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n List all packages by installed size (Bytes) on rpm distros dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1n List all packages by installed size (KBytes) on deb distros dd bs=1 seek=2TB if=/dev/null of=ext3.test Create a large test file (taking no space) > file truncate data of file or create an empty file CD/DVD Command What is does gzip < /dev/cdrom > cdrom.iso.gz Save copy of data cdrom mkisofs -V LABEL -r dir | gzip > cdrom.iso.gz Create cdrom image from contents of dir mount -o loop cdrom.iso /mnt/dir Mount the cdrom image at /mnt/dir (read only) wodim dev=/dev/cdrom blank=fast Clear a CDRW gzip -dc cdrom.iso.gz | wodim -tao dev=/dev/cdrom -v -data - Burn cdrom image cdparanoia -B Rip audio tracks from CD to wav files in current dir wodim -v dev=/dev/sr0 -audio -pad *.wav Make audio CD from all wavs in current dir oggenc --tracknum=$track track.cdda.wav -o track.ogg Make ogg file from wav file for i in *.mp3; do mpg123 --rate 44100 --stereo --buffer 3072 --resync -w "$(basename $i .mp3).wav" $i; done Decode mp3 files to 16-bit, stereo, 44.1 kHz waves for i in *.mp3; do lame --decode $i ``basename $i .mp3``.wav; done Decode mp3 files to 16-bit, stereo, 44.1 kHz waves normalize -m *.wav Normalise levels in wavs, mix mode is loud as possible Locales Command What is does printf "%'d\n" 1234 Print number with thousands grouping appropriate to locale BLOCK_SIZE=\'1 ls -l Use locale thousands grouping in ls. See also l echo "I live in$(locale territory)" Extract info from locale database LANG=en_IE.utf8 locale int_prefix Lookup locale info for specific country. See also ccodes locale -kc $(locale | sed -n 's/\(LC_.\{4,\}\)=.*/\1/p') | less List fields available in locale database Dates and Times Command What is does cal -3 Display a calendar cal 9 1752 Display a calendar for a particular month year date -d fri What date is it this friday [ $(date -d '12:00 today +1 day' +%d) = '01' ] || exit exit a script unless it’s the last day of the month date --date='25 Dec' +%A What day does xmas fall on, this year date --date='@2147483647' Convert seconds since the epoch (1970-01-01 UTC) to date TZ='America/Los_Angeles' date What time is it on west coast of US (use tzselect to find TZ) date --date='TZ="America/Los_Angeles" 09:00 next Fri' What’s the local time for 9AM next Friday on west coast US Images Most of these rely on the imagemagick cli programs. ...

February 18, 2017 · 25 min

C

Update: 2022-04-26: Overhauling to be simplier and bsd/clang friendly. Rules of engagement Style The language Basic Types Integer Types Real and Complex Floating Types void Memory Access Operators Strings The Pre Processor Macros Patterns vtables person_s.h print_vtable.h print_vtable.c main.c Libraries C standard library C POSIX library Unit Testing Sample C code Rules of engagement How I program C by Eskil Steenberg Notes on Programming in C by Rob Pike The Ten Commandments for C Programmers by Henry Spencer Style suckless FreeBSD man 9 style The language Basic Types Integer Types C99 with stdbool.h introduced boolean type _Bool (1 byte), and macros true (1) and false (0). ...

November 26, 2016 · 9 min

Shay Banon on Innovation

Some great wisdom imparted by Shay Banon (creator of Elasticsearch). Be bored. To promote innovation. Open source and building a critical mass. Be committed. You need to care for it now; IRC, forums, negative feedback, bugs. The benevolent dicator model (BDM) versus the democracy with a leader model. Be distributed. Choose a useful (and normally hard) problem to solve. Best way to learn is to actually build something. Double down on passion. Recruit passionate people (e.g. story about the guy who paid for Elastic training off his own back). Videos are for collaboration. Simple things, should be simple. Not easy though. Hierarchy matters. Humans can’t make decisions in groups. IT is obsessed with whats next. You only need to look backwards for answers.

November 22, 2016 · 1 min