Zum Inhalt

Commands Collection

Collection of helpful Linux commands.

List File With Leading Line Numbers

$ nl -w2 -s"| " testfile.txt
 1| This is a test file
 2| with line break.

List group of files

$ find . -type f | awk -F. '{print $NF}' | sort | uniq -c | sort -n

Generate and Read QR Codes

# Generate
$ echo "some data" | base64 -w 0 | qrencode -l Q -t SVG -o /tmp/qr.svg

# Read
$ zbarimg -q /tmp/qr.svg | cut -c 9- | base64 -d

Generate Duplex PDF from Single Page Scan

# Change order of even pages
$ /usr/bin/pdftk EvenPages.pdf cat end-1 output BackWardsEvenPages.pdf

# Merge even and odd pages
$ /usr/bin/pdftk ODD=OddPages.pdf EVEN=backWardsEvenPages.pdf shuffle ODD EVEN output FinalDocument.pdf

# Remove last blank page, if necessary
$ /usr/bin/pdftk FinalDocument.pdf cat 1-r2 output FinalDocumentWithoutLast.pdf

Media Files

Download Videos

Provide a selection of possible variations of audio and video format.

$ yt-dlp -f- <URL>
Download with multiple audio tracks
yt-dlp -f "AUDIO_ID_1+AUDIO_ID_2+AUDIO_ID_3+VIDEO_ID" --audio-multistreams <URL> 

docker run --user="1000:1000" --rm -it --volume=.:/downloads:rw jauderho/yt-dlp:latest -f "bv*+ba/best" "${1}"

Rename mass files

Rename Media Files to Create Date

$ exiftool -d '%Y-%m-%d_%H%M%S.%%e' '-filename<CreateDate' -v 1 *
$ exiftool -d '%Y-%m-%d_%H%M%S.%%e' '-filename<DateTimeOriginal' -v 1 *

Rename File based on Modified Date

for f in *.jpg
do
    mv -n "$f" "$(date -r "$f" +"%Y-%m-%d_%H%M%S").jpg"
done

Copy Metadata Media

$ exiftool -TagsFromFile source.mp4 -all:all -overwrite_original destination.mp4

Geotag Pictures

$ exiftool -geotag=geolocation.gpx -geosync=-1 ./photos/
-geosync defines offset in hours

Create Empty File

# create file with size but does not allocate space on disc
truncate -s 1G foo.file

# create file with size also llocate space on disc
fallocate -l 1G foo.file

Remove DRM from PDF

# Login to Adobe DRM
$ adept_activate --username ADOBE_LOGIN_USERNAME --password ADOBE_LOGIN_PASSWORD

# Download PDF from ASCM File
$ acsmdownloader --acsm-file downloadfile.ascm --output-file outputfile

# Remove DRM
$ adept_remove TMPOUT

Rename File in Folder to Lowercase

$ find . -type f -exec perl-rename -v 'y/A-Z/a-z/' {} \;

Convert

Convert AVI to mp4

$ ffmpeg -i input.avi -b 800k output.mp4

Convert Markdown to PDF

# Set alias
$ alias pandocker="docker run --rm --volume "`pwd`:/data" --user `id -u`:`id -g` pandoc/latex:2.6"

#Use the command
$ pandocker in.md -o out.pdf

Clear log journal

$ sudo journalctl --rotate --vacuum-time=1s

ZFS

Destroy all Snapshots from Dataset

$ zfs list -H -o name -t snapshot <POOL/DATASET> | xargs -n1 sudo zfs destroy -v -n

Remote RDP connection Gnome Shell

# Enable RDP
$ gsettings set org.gnome.desktop.remote-desktop.rdp enable true
$ gsettings get org.gnome.desktop.remote-desktop.rdp view-only false

# Get Fingerprint of Encryption Certificate
$ openssl x509 -in  ~/.local/share/gnome-remote-desktop/certificates/rdp-tls.crt -noout -text -fingerprint -sha256

# Disable RDP
$ gsettings set org.gnome.desktop.remote-desktop.rdp enable false
$ gsettings get org.gnome.desktop.remote-desktop.rdp view-only true