File Operations

Find and Replace Text

sed -i 's/old-text/new-text/g' filename

Replace all occurrences of ‘old-text’ with ’new-text’ in a file

find . -name "*.txt" -type f -mtime -7

Find all .txt files modified in the last 7 days

Move files with rsync and ssh

rsync -avz -e "ssh -p 22" <source_file_or_dir> user@<remote_host>:/<remote_dir>/

Rsync via ssh. Port 22 is default but is added as a reminder that you might need to change to something else.

# Find and hardlink duplicates
rdfind -makehardlinks true /path/to/drive

# Just identify duplicates
rdfind -dryrun true /path/to/drive

Backup to a cloud provider with encrypted filenames

rclone copy \
    /source/path crypt:backup \
    --crypt-remote "gdrive:encrypted" \
    --crypt-password "your-password" \
    --crypt-filename-encryption standard \
    --crypt-directory-name-encryption true \
    --transfers 4 \
    --checkers 8 \
    --tpslimit 10

Needs config on the cloud provider: -> $ rclone config and read https://rclone.org/

Deduplicate files across multiple remotes

rclone dedupe \
    --dedupe-mode newest \
    remote1:path remote2:path remote3:path \
    --dry-run \
    --check-sum \
    -P

Critical sync with monitoring and notifications to ntfy.sh

rclone sync \
    /local/path remote:backup \
    --monitor \
    --monitor-notify-url="https://your-ntfy-server.com/your-topic" \
    --monitor-notify-headers="Authorization: Bearer tk_your_access_token" \
    --monitor-min-age 5m \
    --use-json-log \
    --log-file="/var/log/rclone-sync.log" \
    --stats 1m

Storage

LVM & LUKS

Loopback devices

In memory-only tmpfs for docker

grub

ipfs

Network

Detailed info on network config

nmcli dev show

Port Scanning

netstat -tulpn | grep LISTEN

List all listening ports and the processes using them

Speed testing

iperf3 -s # run as server/receiving side
iperf3 -c <server_hostname> -f M -u -R # run speed test between both hosts / format output in Mbit / use UDP instead of default UDP / add -R to reverse the direction (server sends data to client)

Speed testing with iperf3. By default it tests on port 5201. Read man page for authentication mechanisms.

Look at traffic on a specific port

sudo tcpdump -i any port 67 or port 68 or port 69 -n

Look at dhcp and tftp traffic (in this example) to see what kind of information is exchanged. Leave out the -n to resolve ip’s.

Live usage

nethogs

Quick HTTP Server

python3 -m http.server 8000

Start a simple HTTP server in the current directory

hugo serve -D

Run hugo locally to see how the generated static site will like like on prod

Process Management

Memory Usage

ps aux | sort -rk 4,4 | head -n 5

Show top 5 processes by memory usage

DNS

DNS config

resolvectl status

See DNS config per NIC

nmcli dev show | grep DNS

pi-hole

docker logs pihole | grep random to find your random pass

Find the random generated pw when launching a container with default settings.

docker exec -it pihole bash
pihole -f

Flush the cache in the container.

vim

Proxmox cli

Get a CT template

pveam update
pveam available
pveam download <template>

List CT’s, VM’s and storage

pct list
qm list
pvesm status

Create a container

pct create 101 local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst \
        --hostname nginx-proxy \
        --cores 2 \
        --memory 2028 \
        --swap 512  \
        --rootfs local-zfs:20 \
        --net0 name=eth0,bridge=vmbr0,ip=192.168.1.10/24,gw=192.168.1.1 \
        --password

Watch out for the ID.

docker.io

Remove and purge everything

# Stop all running containers
docker stop $(docker ps -a -q)

# Remove all containers
docker rm $(docker ps -a -q)

# Remove all images
docker rmi $(docker images -q) -f

# Remove all stopped containers, unused networks, dangling images, and build cache
docker system prune -a

# If you also want to remove volumes
docker system prune -a --volumes

Be careful when using these commands as they will remove:

All stopped containers
All networks not used by at least one container
All images without at least one container associated with them
All build cache
All volumes (if –volumes is specified)

Tree view of docker networks and containers attached

docker network ls --format '{{.Name}}' | while read net; do \ 
    echo "Network: $net"; \ 
    docker network inspect "$net" --format '{{range .Containers}}{{.Name}}{{"\n"}}{{end}}' | sed 's/^/  └─ /' || echo "  └─ (none)"; 
done