Skip to content

Instantly share code, notes, and snippets.

@egobude
Last active August 3, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egobude/06bcae077431225dc1150a446880ac70 to your computer and use it in GitHub Desktop.
Save egobude/06bcae077431225dc1150a446880ac70 to your computer and use it in GitHub Desktop.
Snippets

Every Day Snippets

tcpdump

Listen on pings

$ tcpdump -i any icmp

Listen on any interface and port 5683

$ tcpdump -v -i any port 5683

natcat

Send package to port

$ nc -z -v -w5 -u xx.xx.xx.xx 5683

Send packge with custom source ip

$ nc -z -v -w5 -s xx.xx.xx.xx -u xx.xx.xx.xx 5683

General

Golang

Docker

Links & videos

Kubernetes

Static ip address per container

version: '2.1'

services:
  nginx:
    image: nginx:latest
    networks:
      migrator_1:
        ipv4_address: 10.177.0.12

networks:
  migrator_1:
    ipam:
      driver: default
      config:
      - subnet: 10.177.0.2/24

Modify docker daemon in the vm (ubuntu)

Datei /etc/default/docker

DOCKER_OPTS="-D -H tcp://10.0.1.13:2375 -H unix:///var/run/docker.sock"

Modify docker daemon in the vm (centos)

Datei /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/docker daemon -H tcp://10.0.1.13:2375 -H unix:///var/run/docker.sock

List/Remove dangling images

docker images -f dangling=true
docker rmi $(docker images -f dangling=true -q)

List/Remove all exited containers

docker ps -a -f status=exited
docker rm $(docker ps -a -f status=exited -q)

List/Remove dangling volumes

docker volume ls -f dangling=true
docker volume rm $(docker volume ls -f dangling=true -q)

Backup container data

./docker-backup afcd5cae93b4 /usr/share/elasticsearch/data elasticsearch 

Bash

Generate random string

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

SCP Copy file from remote server to local

scp user@homeip:/path/to/file /local/path/

SCP Copy file from local to remote

scp test.txt foo@bar.de:tmp/test.txt

Exclude .svn, .git and other VCS junk for a pristine tarball

tar --exclude-vcs -czvf Packages.tar.gz Packages/      

Exlude folders from tar.gz

tar -czvf t4gdoc.tar.gz doc/ --exclude="doc/media/image" --exclude="doc/files" --exclude="doc/cache" --exclude="doc/_sqlAdmin"

Löscht alle "*" Dateien im Ordner, die älter als 60 Tage sind

find /home/backup -type f \( -name '*' \) -ctime +60 -exec rm {} \;

Dateianzahl - Anzahl der Dateien ermitteln

find /verzeichnis -type f | wc -l

Verzeichnisanzahl - Anzahl der Verzeichnisse ermitteln

find /verzeichnis -type d | wc -l

Ordnergröße herausfinden

du -h /verzeichnis 

Festplattenspeicher auslesen

df -h

Verzeichnisabgleich

rsync -a -v --stats --progress --delete "/mnt/hda1/Eigene Dateien/Fotos/" /mnt/sda5/Fotos/

Mac

Clear DNS Cache

sudo killall -HUP mDNSResponder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment