“some usefull commands for daily work at most”

listen:

## find text in files
> grep -rnw './' -e 'sometext'

## cut first digit in file
> sed 's/^.\{,1\}//' foo

## math
> ((x=1028*6))|echo $x

## create self signed certificate
ipaddr=example.com
openssl req \
      -x509 -nodes \
      -subj "/C=DE/ST=Germany/L=Magdeburg/O=x33u/OU=webdev/CN=$ipaddr" \
      -newkey rsa:4096 \
      -keyout $ipaddr.key \
      -out $ipaddr.crt \
      -days 365

## certbot
> certbot certonly --rsa-key-size 4096 --webroot --agree-tos --no-eff-email --email user@mail -w /var/www/www.x33u.org -d www.x33u.org

## rar bash in same folder
> for f in *.rar; do unrar x -pPASSWORD -o- "$f"; done

## export PATH var
export PATH="$PATH:/foo/bar"

## rar bash in subfolder (script)
---
#!/bin/bash

SAVEIFS=$IFS #newpart
IFS=$(echo -en "\n\b")
for i in $(find $(pwd) -name '*.rar') #old part
do
cd $(dirname $i)
unrar x -o- $i
    done
IFS=$SAVEIFS #new part again
---

## use mmv to bash rename
> mmv '*' '#1.mp4' && mmv '*.mp4.mp4' '#1.mp4'

## rename with count (script)
---
#!/bin/bash
i=1
for File in $(ls *.mkv)	# Filetype angeben
do
mv ${File} NAME-0${i}.mkv	# Endung angeben
i=$((i+1));# Hochzählen
done
---

## glitch in eos
> gsettings set org.gnome.settings-daemon.plugins.cursor active false \
&& gsettings set org.gnome.settings-daemon.plugins.cursor active true

## resolution scaling (scale=1)
> gsettings set org.gnome.desktop.interface scaling-factor 1

## show graphics
> lspci -nnk | grep "VGA\|'Kern'\|3D\|Display" -A2

## eos apt error (script)
---
#!/bin/bash
rm -rf /var/lib/dpkg/updates/*
rm -rf /var/lib/apt/lists/*
rm /var/cache/apt/*.bin
apt-get clean
apt-get autoremove
apt-get update
dpkg --configure -a
apt-get install -f
if still getting same error then try
dpkg --remove --force-remove-reinstreq package_name  
---

## rpi1 overclock (old)
arm_freq=1000
core_freq=500
sdram_freq=500
over_voltage=6    


## heimdall chainfire
> heimdall flash --no-reboot --RECOVERY recovery.img --CACHE cache.img.ext4

## rm dupes with fdupes
> fdupes -r -d -N /path/to/files

## ffmpeg_crf-19:384k (script)
---
for i in *.mkv;
do name=`echo $i | cut -d'.' -f1`;
echo $name;
ffmpeg -i "$i" -c:v libx265 -preset superfast -map_chapters -1 -crf 19 -c:a libfdk_aac -b:a 384k "${name}x265.mkv";
done
---

## ffmpeg_crf-20-map:audio:384k (script)
---
for i in *.mkv;
do name=`echo $i | cut -d'.' -f1`;
echo $name;
ffmpeg -i "$i" -map 0:0 -map 0:1 -c:v libx265 -preset superfast -map_chapters -1 -crf 20 -c:a libfdk_aac -b:a 384k "${name}x265.mkv";
done
---

## journalctl live syslog
> journalctl -u dnsmasq.service -f

## ohmyzsh themes
ZSH_THEME="xiong-chiamiov-plus"
ZSH_THEME="ys"
ZSH_THEME="mortalscumbag"

## temp odroid xu4
> cat /sys/class/thermal/thermal_zone0/temp | sed -e s#000\$##
> watch 'cat /sys/class/thermal/thermal_zone0/temp | sed -e s#000\$##'

## wifi with create_ap
> create_ap -m bridge -w 2 wlan0 eth0 <WLAN-NAME> <WLAN-PASSWORD> --country DE --no-dns -c 9 --daemon

## raspi touchscreen rotate
lcd_rotate=2

## raspi terminal output to another screen
> tty
> exec 1>/dev/tty1

## search for content in files
> grep -l -i suchtext *.txt

## calibre python batch pdf => epub
#!/usr/bin/python
import os, time, glob, subprocess

files = glob.glob('*.pdf')

workers = []
while files or workers:
    while len(workers) < 4 and files:
        f = files[0]
        files = files[1:]
        w = subprocess.Popen(['ebook-convert', f,
            os.path.splitext(f)[0]+'.epub'])
        workers.append(w)
    for w in list(workers):
        if w.poll() is not None:
            workers.remove(w)
    time.sleep(0.1)


## hcloud examples
> hcloud server create \                         
            --name owl-001 \
            --image centos-7 \
            --datacenter hel1-dc2 \
            --location hel1 \
            --type ccx21 \
            --ssh-key 'AAAAB3NzaC1==' \
            --start-after-create

## dns challange
> certbot -d oo.x33u.org --manual --preferred-challenges dns certonly

## dns challange non interactive
> certbot -d oo.x33u.org --manual --preferred-challenges dns certonly --non-interactive --agree-tos -m moonmaster@example.com

## reflector
> reflector --latest 200 --protocol http --protocol https --sort rate --save /etc/pacman.d/mirrorlist
> reflector --country France --country Germany --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist

## export PATH (debian default)
> export PATH=/usr/local/bin:/usr/sbin:/sbin:/usr/bin:/bin:

## add path
> export PATH="/foo/bar/:$PATH"

## luks encrypt
> cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 -y /dev/sdX

## create .htpasswd basic
> htpasswd -c .htpasswd username
> printf "username:`openssl passwd -apr1`\n" >> .htpasswd

## create .htdigest
> htdigest -c /etc/nginx/htdigestuser.pwd "HTTP Digest Access" username

## create .htdigest script without apache-tools
#!/bin/bash

echo "Create an Apache-friendly Digest Password Entry"
echo "-----------------------------------------------"

# get user input, disabling tty echoing for password
read -p "Enter username: " UNAME
read -p "Enter Apache AuthName: " AUTHNAME
read -s -p "Enter password: " PWORD; echo

printf "\n%s:%s:%s\n" \
  "$UNAME" \
  "$AUTHNAME" \
  $(printf "${UNAME}:${AUTHNAME}:${PWORD}" | openssl dgst -md5)

## upgrade openwrt
> opkg update
> opkg list-upgradable
> opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade

## git pull config
> git config --global pull.ff only

## dirty share
> python -m http.server 8080
> python -m http.server --directory ./ 8080