357 lines
8.9 KiB
Plaintext
357 lines
8.9 KiB
Plaintext
; ===========================
|
|
; NIXOS
|
|
; ===========================
|
|
|
|
% nixos-rebuild
|
|
# Rebuild a flake system derivation
|
|
sudo nixos-rebuild <type> --flake .#<flake>
|
|
$ type: echo -e "switch\nbuild\nboot"
|
|
$ flake: echo -e "nixinator\nnixtop"
|
|
|
|
% nh
|
|
# Rebuild the system using nh
|
|
nh os <mode>
|
|
$ mode: echo -e "switch\nbuild\nboot"
|
|
|
|
% nh
|
|
# Clean the nix store
|
|
nh clean <mode>
|
|
$ mode: echo -e "all\nuser"
|
|
|
|
% nix
|
|
# Find out why a package is included in the closure when building the system derivation
|
|
nix why-depends /run/current-system nixpkgs#<package>
|
|
|
|
% nixos
|
|
# Find the storepath of an executable in the users path
|
|
readlink -f $(which <executable>)
|
|
$ executable: bash -c "compgen -c"
|
|
|
|
% nixos
|
|
# Find the wanted dynamic libraries of an executable in the users path
|
|
ldd $(readlink -f $(which <executable>))
|
|
$ executable: bash -c "compgen -c"
|
|
|
|
% nix-tree
|
|
# Browse closures in the nix store sorted by size
|
|
nix-tree
|
|
|
|
% nps
|
|
# Search in nixpkgs
|
|
nps -e "<package>"
|
|
|
|
% nix-search-tv
|
|
# Search in nixpkgs, nur, nixos and home-manager
|
|
nix-search-tv print --indexes 'nixos,home-manager,nixpkgs,nur' | fzf --preview 'nix-search-tv preview {}' --scheme history
|
|
|
|
% nvd
|
|
# Compare the current NixOS generation to another one
|
|
nvd diff /run/current-system ./result
|
|
|
|
% nurl
|
|
# Generate a nix fetcher section
|
|
nurl "<url>"
|
|
|
|
% nurl
|
|
# Generate a nix fetcher section for a specific revision
|
|
nurl "<url>" "<rev>"
|
|
|
|
% nix-alien
|
|
# Run an unpatched binary on NixOS
|
|
nix-alien-ld -- <binary>
|
|
$ binary: eza -f -1
|
|
|
|
% nix repl
|
|
# Enter a repl with loaded NixFlake
|
|
nix repl --extra-experimental-features "flakes" /home/christoph/NixFlake
|
|
|
|
; ===========================
|
|
; SYSTEMD
|
|
; ===========================
|
|
|
|
% systemd
|
|
# List failed system units
|
|
sudo systemctl --failed
|
|
|
|
% systemd
|
|
# List failed user units
|
|
systemctl --user --failed
|
|
|
|
% systemd
|
|
# List system errors
|
|
sudo journalctl -p 3 -xb
|
|
|
|
% systemd
|
|
# List kernel errors
|
|
sudo journalctl -p 3 -xb -k
|
|
|
|
% systemd
|
|
# List system unit errors
|
|
sudo journalctl -xb --unit=<unit>
|
|
$ unit: sudo systemctl list-units --type=service --all --full --no-pager --legend=false --plain | awk -F' ' '{print $1}'
|
|
|
|
% systemd
|
|
# List user unit errors
|
|
journalctl -xb --unit=<unit>
|
|
$ unit: systemctl --user list-units --type=service --all --full --no-pager --legend=false --plain | awk -F' ' '{print $1}'
|
|
|
|
; ===========================
|
|
; SHELL
|
|
; ===========================
|
|
|
|
% shell
|
|
# Launch a detached process with suppressed output
|
|
<command> &>/dev/null &; disown
|
|
|
|
% shell
|
|
# Generate a large text file
|
|
yes "The quick brown fox jumps over the lazy dog" | head -c <size> > <output>
|
|
|
|
% shell
|
|
# For-loop in fish shell
|
|
for o in <objects>; <action>; end
|
|
|
|
% fd
|
|
# Find files larger or smaller than a specified size in the current directory
|
|
fd --type file --size <mode><size> -- "<regex>" .
|
|
$ mode: echo -e "+\t\tFind Larger Files\n-\t\tFind Smaller Files" --- --column 1
|
|
|
|
% fd
|
|
# Find .desktop files of an application
|
|
fd ".*\.desktop" / | rg --trim --pretty "<application>"
|
|
|
|
% gdu
|
|
# Visualize storage usage on all mounted disks
|
|
sudo gdu -d
|
|
|
|
% duf
|
|
# List all mounted devices
|
|
sudo duf
|
|
|
|
% duf
|
|
# Display INode information of all mounted devices
|
|
sudo duf -inode
|
|
|
|
% awk
|
|
# Select a column
|
|
awk -F<separator> '{print $<print>}'
|
|
$ separator: echo -e "' '\t\tWhitespace\n'[ ]'\t\tSingle Space\n'\\\t'\t\tTabs" --- --column 1
|
|
|
|
% sort
|
|
# Remove duplicate lines
|
|
sort -u
|
|
|
|
% uname
|
|
# Determine the current Linux kernel version
|
|
uname -r
|
|
|
|
% mime
|
|
# Determine the mime-type of a file
|
|
file --mime-type <file>
|
|
$ file: eza -f -1
|
|
|
|
% mime
|
|
# Query the default app for a mime type
|
|
xdg-mime query default <mimetype>
|
|
|
|
% mime
|
|
# Query the default app for a file
|
|
xdg-mime query default $(file --mime-type <file> | awk -F' ' '{print $2}')
|
|
$ file: eza -f -1
|
|
|
|
% ouch
|
|
# Extract an archive
|
|
ouch decompress "<archive>"
|
|
$ archive: eza -f -1
|
|
|
|
% pastel
|
|
# Generate a color
|
|
pastel color <color>
|
|
$ color: pastel list
|
|
|
|
% pastel
|
|
# Generate an adjacent color
|
|
pastel color <color> | pastel <mode>
|
|
$ color: pastel list
|
|
$ mode: echo -e "complement\ntextcolor"
|
|
|
|
% pastel
|
|
# Generate a color gradient
|
|
pastel gradient <a> <b> | pastel format hex
|
|
$ a: pastel list
|
|
$ b: pastel list
|
|
|
|
% ripdrag
|
|
# Drag & drop file from the terminal
|
|
ripdrag <file>
|
|
$ file: eza -1
|
|
|
|
% nvidia-smi
|
|
# Monitor Nvidia GPUs
|
|
watch -d -c -n 0.5 nvidia-smi
|
|
|
|
% lsattr
|
|
# List file/directory attributes
|
|
lsattr <file>
|
|
$ file: eza -1
|
|
|
|
% chattr
|
|
# Make files/directories mutable
|
|
sudo chattr -R -i <file>
|
|
$ file: eza -1
|
|
|
|
; ===========================
|
|
; SECRETS
|
|
; ===========================
|
|
|
|
% gpg
|
|
# Generate a new GPG key
|
|
gpg --full-generate-key
|
|
|
|
% gpg
|
|
# List GPG keys
|
|
gpg <mode> --keyid-format=long
|
|
$ mode: echo -e "--list-keys \tList public keys\n--list-secret-keys\tList private keys" --- --column 1
|
|
|
|
% gpg
|
|
# Delete GPG key
|
|
gpg --delete-secret-and-public-key <key>
|
|
|
|
% gpg
|
|
# Export GPG key
|
|
gpg <mode> --armor --output <output> <key>
|
|
$ mode: echo -e "--export \tExport public key\n--export-secret-keys\tExport private key" --- --column 1
|
|
|
|
% sops
|
|
# Edit secrets.yaml
|
|
sops ~/NixFlake/system/modules/sops-nix/secrets.yaml
|
|
|
|
% sops
|
|
# Rekey secrets.yaml
|
|
sops updatekeys ~/NixFlake/system/modules/sops-nix/secrets.yaml
|
|
|
|
% ssh
|
|
# Generate a new SSH key
|
|
ssh-keygen -t <type> -C "<comment>"
|
|
$ type: echo -e "ed25519 \tElliptic Curve\nrsa -b 4096\t4096 bit RSA" --- --column 1
|
|
|
|
% age
|
|
# Generate a new age key
|
|
age-keygen -o <file>
|
|
|
|
% age
|
|
# Print the public key of an age key
|
|
age-keygen -y <key>
|
|
$ key: eza -f -1
|
|
|
|
% mkpasswd
|
|
# Print the hash of a password
|
|
echo "<password>" | mkpasswd -s
|
|
|
|
; ===========================
|
|
; CODE
|
|
; ===========================
|
|
|
|
% code
|
|
# Disassemble an object file
|
|
objdump -d -S -M <arch>,<syntax> "<file>" | bat -l nasm
|
|
$ arch: echo -e "x86-64\t\t64 Bit\ni386\t\t32 Bit\ni8086\t\t16 Bit" --- --column 1
|
|
$ syntax: echo -e "intel\t\tIntel Syntax\natt\t\tAT&T Syntax" --- --column 1
|
|
$ file: eza -f -1
|
|
|
|
; ===========================
|
|
; DOCS
|
|
; ===========================
|
|
|
|
% docs
|
|
# Extract svg figure from pdf page
|
|
pdftocairo -f <page> -l <page> -svg "<input>" "<output>"
|
|
$ input: eza -f -1
|
|
|
|
; ===========================
|
|
; YT-DLP
|
|
; ===========================
|
|
|
|
% yt-dlp
|
|
# Download mp4 video in best quality
|
|
yt-dlp -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' --recode-video mp4 "<url>"
|
|
|
|
% yt-dlp
|
|
# Download mp3 video in best quality
|
|
yt-dlp -f 'ba' --extract-audio --audio-format mp3 "<url>"
|
|
|
|
% spotdl
|
|
# Download spotify playlist
|
|
mkdir -p "<name>" && cd "<name>" && spotdl --client-id (cat /home/christoph/.secrets/spotify_client_id) --client-secret (cat /home/christoph/.secrets/spotify_client_secret) --user-auth --cookie-file /home/christoph/.secrets/youtube_music_cookies --format opus --bitrate disable --threads 24 --m3u "<name>" download "<url>" && cd ..
|
|
|
|
% spotdl
|
|
# Download spotify item
|
|
mkdir -p "<name>" && cd "<name>" && spotdl --client-id (cat /home/christoph/.secrets/spotify_client_id) --client-secret (cat /home/christoph/.secrets/spotify_client_secret) --user-auth --cookie-file /home/christoph/.secrets/youtube_music_cookies --format opus --bitrate disable --threads 24 download "<url>" && cd ..
|
|
|
|
; ===========================
|
|
; FFMPEG
|
|
; ===========================
|
|
|
|
% ffmpeg
|
|
# Create a slow motion version of a video with interpolated/blended frames
|
|
ffmpeg -i "<input>" -filter:v "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=<doublefps>',setpts=2*PTS" output.mp4
|
|
$ input: eza -f -1
|
|
|
|
% ffmpeg
|
|
# Detect black bar dimensions automatically by looking at the first 10 frames
|
|
ffmpeg -i "<input>" -vframes 10 -vf cropdetect -f null -
|
|
$ input: eza -f -1
|
|
|
|
% ffmpeg
|
|
# Preview video with applied crop settings
|
|
ffplay -vf crop=<width>:<height>:<x>:<y> "<input>"
|
|
$ input: eza -f -1
|
|
|
|
% ffmpeg
|
|
# Re-encode the video with applied crop settings
|
|
ffmpeg -i "<input>" -vf crop=<width>:<height>:<x>:<y> -c:a copy output.mp4
|
|
$ input: eza -f -1
|
|
|
|
% ffmpeg
|
|
# Reencode and compress the video using the h265 codec
|
|
ffmpeg -i "<input>" -vcodec libx265 -crf <quality> "out_<input>"
|
|
$ input: eza -f -1
|
|
$ quality: echo -e "24\n25\n26\n27\n28\n29\n30\n"
|
|
|
|
% ffmpeg
|
|
# Reencode and compress multiple videos using the h265 codec
|
|
fish -c "for name in <files>; ffmpeg -i '$name' -vcodec libx265 -crf <quality> 'out_$name'; end"
|
|
$ quality: echo -e "24\n25\n26\n27\n28\n29\n30\n"
|
|
|
|
; ===========================
|
|
; DISKS
|
|
; ===========================
|
|
|
|
% nvme
|
|
# Query NVME disk SMART information
|
|
sudo nvme smart-log /dev/<drive>
|
|
$ drive: eza -1 /dev | rg --trim -e "^nvme\dn\dp\d" | sd "n\dp\d" "" | sort -u
|
|
|
|
% nvme
|
|
# Query NVME SSD used percentage
|
|
sudo nvme smart-log /dev/<drive> | rg --trim "percentage_used"
|
|
$ drive: eza -1 /dev | rg --trim -e "^nvme\dn\dp\d" | sd "n\dp\d" "" | sort -u
|
|
|
|
% cryptsetup
|
|
# Open LUKS device
|
|
sudo cryptsetup luksOpen /dev/<drive> <label>
|
|
$ drive: eza -1 /dev | rg --trim -e "^nvme\dn\dp\d" | sd "n\dp\d" "" | sort -u
|
|
|
|
% cryptsetup
|
|
# Close LUKS device
|
|
sudo cryptsetup luksClose <label>
|
|
|
|
% disko
|
|
# Partition and format disks
|
|
sudo disko --mode disko --flake .#<target>
|
|
|
|
% impermanence
|
|
# Find directories not yet persisted (individual files are always listed!)
|
|
sudo fd --one-file-system --base-directory <dir> --type f --hidden --exclude "{tmp,etc/passwd,.cache}"
|
|
$ dir: echo -e "/\n/home/christoph"
|