Wiki

A universe of ideas

User Tools

Site Tools


computer:bash_snippets

This is an old revision of the document!


Bash snippets

Play YouTube Playlists

youtube-dl \
    -f 'bestvideo[vcodec=vp9]+bestaudio[acodec=opus]' \
    --merge-output-format mkv \
    -o 'id_%(playlist_index)s - %(title)s (%(id)s).%(ext)s' \
    --playlist-start 1 \
    --playlist-end 19 \
    'https://youtube.com/playlist/url'
mkvmerge -o all_001-019.mkv \[ id_* \]
mpv --save-position-on-quit all_001-019.mkv

Geeignete Formate finden:

youtube-dl -F 'https://youtube.com/playlist/url' | \
grep -E '^[0-9]+' | \
sort -nr | \
uniq -w 10 -c | \
sort -nrs

Order files and directories recursive by date

Order all files and directories in a certain subdirectory by date of last modification

find <dir> -print0 | xargs -0 ls -ldt | less

Proxy via SSH

ssh -D 4242 lmu

Im Browser kann dann der SOCKS Proxy “localhost” auf “4242” eingestellt werden.

List most used bash commands

history | cut -c 8- | cut -f 1 -d ' ' | sort | uniq -c | sort -n -r

The result:

    101 l
     69 c
     40 mupdf
     24 mv
     16 sudo
     16 history
     12 vlc
     12 rm
     12 man
     10 zip
     10 pdflatex
      9 ps
      9 exit
      9 echo
      7 while
      7 ssh
      7 pacman
      7 mplayer
      7 ln
      6 wget
      6 umount
      6 cat
      5 sml
      5 mkdir
      5 acroread
....

SSH key

ssh-keygen
ssh-keygen -t ecdsa
ssh-keygen -t ed25519
 
ssh-copy-id -i ~/.ssh/id_rsa.pub ${R_USER}@${R_HOST}

List modified files

pacman -Qii | grep ^MODIFIED | sort
find /etc/ -type f | while read f ; do pacman -Qo "$f" >/dev/null 2>&1 || echo "$f" ; done

Install termcaps

infocmp rxvt-unicode-256color | s $YOUR_HOST "cat >~/tmp-term-info && tic ~/tmp-term-info && rm ~/tmp-term-info"

Pacman

Removing packages and their dependencies

pacman -Rs

Clean the package cache of packages that are not currently installed

pacman -Sc

Clean the entire package cache

pacman -Scc

Parameterübergabe

rsync

  • -X / --xattr
  • -S
    Sparse Files
  • -H
    Hard links
  • -a
    Archive
  • -u / --update
  • -A / --acls
  • -E
    Speichere executable bit mit
  • --progress

rsync -aAxuHS --progress

Bling stat Beep

Müll deaktivieren

chmod a-x /usr/lib/colord/colord
chmod a-x /usr/lib/gvfs/gvfsd
chmod a-x /usr/lib/gvfs/gvfsd-*
chmod a-x /usr/bin/kactivitymanagerd
chmod a-x /usr/lib/at-spi2-core/at-spi-bus-launcher
chmod a-x /usr/bin/knotify4

Network monitoring

http://www.binarytides.com/linux-commands-monitor-network/

Programm Per Interface Per Stream Per Process Non Root Kommentar
iptraf-ng (V) (V) (X) (X) GUI
nmon (V) (X) (X) Nicht seine hauptaufgabe
iftop
tcptrack
nethogs (X) (X) (V) (X) Zeigt nur neue Verbindungen
pktstat (V) (V) (X) (X)
bmon (V) (X) (X) (V) Wie nload, nur ohne farbe und ohne verständlich, aber mit mehr details
slurm (V) (X) (X) (V) Wie nload, nur mit farbe und ohne verständlich
nload (V) (X) (X) (V) Es ist klar ob Bit oder Byte, wie slurm
  • ngrep -d eth0 -x port 80
  • tcpflow -i eth0 -C -e port 80

Iperf server: http://ping.online.net/

diff & patch

  • diff -u original.c new.c > original.patch
  • patch -p1 < baz.patch

Find

In small files

find ...  -size -20k -type f -exec grep ... {} + 

Files not belonging to the current user

find \! -user $(whoami) -exec ls --color=always -ld {} +

oder mit meinem notmine alias.

Big files

find / -type f -size +300M -exec ls --color=always -l {} +

pentadactyl

http://nakkaya.com/2014/01/26/pentadactyl-configuration/

set scrollsteps=1
set scrolltime=0
set incfind
set hlfind

SSL

nmap --script ssl-enum-ciphers -p 443 onmars.eu
sslscan --no-failed onmars.eu
openssl ciphers | tr : '\n' | sort

SCP / sshfs / sftp absichern

wget https://github.com/mysecureshell/mysecureshell/archive/v2.00.tar.gz
tar -xvf v2.00.tar.gz
cd mysecureshell-2.00
## root check aus install.sh entfernen
mkdir -p "$HOME/mysecureshell/"{bin,etc}
./configure \
  --prefix="$HOME/mysecureshell" \
  --with-conffile="$HOME/mysecureshell/sftp_config" \
  --with-logfile="$HOME/mysecureshell/sftp-server.log" \
  --with-shutfile="$HOME/mysecureshell/sftp.shut" \
  --exec-prefix="$HOME/mysecureshell"
make all

Config

## http://mysecureshell.readthedocs.io/en/latest/index.html
 
<Default>
    Home            /                                                         
    ApplyFileSpec   OnlyData
</Default>
 
<FileSpec OnlyData>
    UseFullPath true
    Order AllowDeny
    Allow "^/(foo/1/?|foo/2/?|bar/baz/?|$|foo/?$|bar/?$)"
    Deny all
</FileSpec>

Zu schlecht für ein dotfile

Hier sind scripte, die zwar eine nette Idee, aber viel zu schlecht für ein dotfile sind.

( pgrep bash | xargs -n 1 pstree -Uangpsu ) | sed 's/^\([ │├─└]*\)\(\({[^,]*\)\|\([^,]*\)\),\([0-9]*\),\([0-9]*\)\(,\(\w*\)\|\)/\1 \x1b[1;30m\3\x1b[0m\x1b[1;37m\4\x1b[0m \x1b[36m\5\x1b[0m \x1b[34m\6\x1b[0m \x1b[33m\8\x1b[0m/'
## https://gitlab.labs.nic.cz/labs/dnssec-validator/issues/38
JAR="`echo ~/.moonchild\ productions/pale\ moon/*.default/extensions/dnssec@nic.cz/chrome/dnssec.jar`"
 
cd "`mktemp -d`"
unzip -q "$JAR"
patch -p1 <<EOF
--- a/content/firefoxOverlay.xul	2015-12-13 03:53:26.236938476 +0100
+++ b/content/firefoxOverlay.xul	2015-12-13 03:54:16.686429894 +0100
@@ -102,7 +102,7 @@
 
 	</popupset>
 
-	<textbox id="urlbar">
+	<statusbar id="status-bar">
 	<box id="urlbar-icons">
 	<!-- DNSSEC button in urlbar -->
 		<hbox id="dnssec-box" role="button"
@@ -121,5 +121,5 @@
         <!-- /stack -->
 	</hbox>
 	</box>
-	</textbox>
+	</statusbar>
 </overlay>
EOF
 
zip "$JAR" content/firefoxOverlay.xul
computer/bash_snippets.1542667396.txt.gz · Last modified: 2020-11-18 18:10 (external edit)