Skip to content

Instantly share code, notes, and snippets.

@chazer
Last active October 25, 2020 16:29
Show Gist options
  • Save chazer/ac7c8c6feb3f9ef0ca742bc6f503f6f3 to your computer and use it in GitHub Desktop.
Save chazer/ac7c8c6feb3f9ef0ca742bc6f503f6f3 to your computer and use it in GitHub Desktop.
Linux cheatsheet

Linux cheatsheet

Fill file with zeros

bash -c 'read blocks blocksize < <(stat -c "%b %B" "$1"); dd if=/dev/zero bs=${blocksize} count=${blocks} of="$1" conv=notrunc status=progress' - /FILE

Create swap file

SWAP_FILE="/swapfile"

# allocate file
sudo fallocate -l 512M "$SWAP_FILE"

# fill file with zeros
sudo bash -c 'read blocks blocksize < <(stat -c "%b %B" "$1"); dd if=/dev/zero bs=${blocksize} count=${blocks} of="$1" conv=notrunc status=progress' - "$SWAP_FILE"

sudo chmod 600 "$SWAP_FILE"

# Create
sudo mkswap "$SWAP_FILE"

# Activate
sudo swapon "$SWAP_FILE"

# Add swap load to fstab file
echo "$SWAP_FILE swap swap defaults 0 0" | sudo tee -a /etc/fstab

# Check
sudo swapon --show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment