Category Archives: Cheat Sheet

dd

Backup / Clone

# clone disk
dd if=/dev/sdX of=/dev/sdY bs=64K conv=noerror,sync status=progress

# backup to file using gzip compression
dd if=/dev/sdX bs=64K conv=noerror,sync status=progress | gzip -c  > /PATH/TO/DRIVE/backup_image.img.gz

# restore from file
gunzip -c /PATH/TO/DRIVE/backup_image.img.gz | dd of=/dev/sdX status=progress

# restore from file without gzip
dd if=/PATH/TO/DRIVE/backup_image.img of=/dev/sdX status=progress

# clone only to the end of last partition
SECTOR_SIZE=$(blockdev --getss /dev/sdX)
# LAST_END=start + size - 1
sfdisk -d /dev/sdX
# parameters for dd
bs="$SECTOR_SIZE" count="$LAST_END"

Mount Image

# Scan
losetup --partscan --find --show backup_image.img

# Free-up
losetup -d /dev/loop0

AutoMySQLBackup

Configuration

```
# Set rotation of daily backups. VALUE*24hours
# If you want to keep only today's backups, you could choose 1, i.e. everything older than 24hours will be removed.
CONFIG_rotation_daily=6

# Set rotation for weekly backups. VALUE*24hours
CONFIG_rotation_weekly=30

# Set rotation for monthly backups. VALUE*24hours
CONFIG_rotation_monthly=90
```

Apache

CLI

# Enable modules
a2enmod ssl
a2enmod rewrite

# Disable autoindex
a2dismod autoindex

# Enable default SSL config
a2ensite default-ssl

Configuration

# HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

svn

========================================
        Subversion (SVN) Cheatsheet
========================================

Checkout
  svn checkout URL [url]

Update working copy
  svn update

Commit changes
  svn commit -m "Changes description"

Working copy status
  svn status

Show diff
  svn diff

Show diff with colors (requires colordiff package)
  svn diff | colordiff

Add new file
  svn add file

Copy file
  svn copy file

Delete file
  svn delete file

Rename / move file
  svn move old_name new_name

Show log (history)
  svn log [file]

Revert local changes
  svn revert file
  svn revert -R directory (recursively)

nmcli

Basic Commands

CommandDescription
nmcliShow general help
nmcli general statusShow overall NetworkManager status
nmcli general hostnameView or set system hostname
nmcli radio allShow Wi-Fi and Bluetooth state
nmcli networking on/offEnable or disable all networking
nmcli connection showList saved connections
nmcli device statusShow status of all devices

Device Management

CommandDescription
nmcli deviceList all devices
nmcli device showShow detailed info for all devices
nmcli device disconnect <device>Disconnect a specific device (e.g. wlan0)
nmcli device connect <device>Connect a specific device

Wi-Fi

CommandDescription
nmcli device wifi listList available Wi-Fi networks
nmcli device wifi connect <SSID> password <password>Connect to a Wi-Fi network
nmcli device wifi connect <SSID> --askConnect to a Wi-Fi network and ask for password
nmcli connection show --activeShow active connections
nmcli connection up <name>Activate a connection
nmcli connection down <name>Deactivate a connection

Connections (Profiles)

CommandDescription
nmcli connection add type ethernet ifname eth0 con-name homeAdd new Ethernet connection
nmcli connection modify <name>Modify connection settings
nmcli connection delete <name>Delete a saved connection
nmcli connection clone <name> <new_name>Clone a connection profile

Reset and Troubleshooting

CommandDescription
nmcli connection reloadReload all connection profiles
nmcli networking off && nmcli networking onRestart networking
nmcli --askPrompt for password or secrets interactively

powercfg

Disable hibernation

powercfg /hibernate off

What sleep states are available?

powercfg /availablesleepstates

What device caused last wake?

powercfg /lastwake

What device blocks sleep?

powercfg /requests

# Ignore driver
powercfg /requestsoverride DRIVER "Realtek High Definition Audio" System

# View ignored drivers
powercfg /requestsoverride

git

Configure

# Config username and email
git config --global user.name jdoe
git config --global user.email john.doe@example.com

# To avoid detected dubious ownership warning
git config --global --add safe.directory "*"

Initialize Repository

git init                     # Create a new Git repository
git clone <url>              # Clone an existing repository

Working with Changes

git status                   # Show the working directory status
git add -A                   # Stage all changes
git add <file>               # Stage a specific file
git reset                    # Unstage all files (keep changes)
git reset <file>             # Unstage a specific file
git mv <source> <dest>       # Rename file
git checkout -- <file>       # Revert local file changes
# Revert changes on single file to previous commit
git checkout <commit-hash> <file>

# Revert changes made by specified commit
git revert <commit-hash>

Commit & History

git commit -m "Message"       # Commit with a message
git log                       # View commit history
git log --oneline             # Compact log view
git log -3 --name-status      # Last 3 changes with file names
git log --follow -p -- <file> # Follow file history

Blame

# Blame from line X to Y
git blame -L X,Y <file>

# Show changes on a file from a specified commit
git show <commit-hash> -- <file>

Push & Pull

git push origin <branch>    # Push changes to the remote branch
git push origin -u <branch> # Push new branch
git pull                    # Fetch and merge changes from remote
git fetch --all             # Fetch all from remote
# Delete branch from remote
git push origin --delete <branch>

Patching

# Patch from uncommitted changes
git diff > changes.patch

# Patch from changes between two commits
git diff commit1 commit2 > changes.patch

Branching

git branch                 # List all branches
git branch <name>          # Create a new branch
git branch -d <name>       # Delete a branch
git checkout <branch>      # Switch to a branch
git checkout -b <name>     # Create and switch to a new branch
git merge <branch>         # Merge a branch into the current one

Tagging

git tag <name>             # Create new tag
git push origin --tags     # Push tags to remote
# Tag with current date / time
git tag PUB_$(date -Format 'yyMMdd')
git tag PUB_$(date -Format 'yyMMdd-HHmm')

Undoing Changes

git restore <file>           # Discard changes in a file
git reset --hard             # Discard all uncommitted changes

Remote Repositories

git remote -v                # Show remote repositories
git remote add origin <url>  # Add a remote repository
git remote rm origin         # Remove a remote repository