I decided to record here useful bash fragments, commands, etc. I kept using and forgetting from time to time... I will enrich it as needed. There is no particular order nor specific explanation. Some might be useful to others. Maybe. Who knows.
Table of contents:
- Arbitrary file binary dump into C array
- Extract some pages from a PDF into a different PDF
- Reduce (compress) the size of a PDF
- Add an empty audio track to a video
- Compress a video taken from your smartphone, striping the audio
- Extract a RPM content into the local directory
- Prepare a patch serie from git to send
- tar all files under git version control
- Monitor consumed DDR bandwidth every seconds (Intel IMC HW counters)
- Extract an ADB (Android) backup
- Optimize JPEG for sharing
Arbitrary file binary dump into C array
To include any file content directly into C arrays.
hexdump -v -e '/1 "0x%02x,"' input
Extract some pages from a PDF into a different PDF
Eg. save some articles from a magazine.
pdfjam -o pages_73-98.pdf original.pdf 73-98
Reduce (compress) the size of a PDF
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Add an empty audio track to a video
Useful to display video on "smart" TV w/o annoying "unsupported audio track" message.
ffmpeg -f lavfi -i anullsrc -i input -shortest -c:v copy -strict -2 -c:a aac output
Compress a video taken from your smartphone, striping the audio
To share over email.
ffmpeg -y -i input -c:v libx264 -preset slow -b:v 300k -vf scale=640:-1 -pass 1 -c:a copy -f mp4 /dev/null && ffmpeg -i input -c:v libx264 -preset slow -b:v 300k -vf scale=640:-1 -pass 2 -an output.mp4
Extract a RPM content into the local directory
rpm2cpio input.rpm | cpio -idmv
Prepare a patch serie from git to send
git format-patch --to=list@list --from --cover-letter -s --thread --subject-prefix="PREFIX" sha1
tar all files under git version control
(PREFIX="$(basename $(readlink -f .))-$(git describe --all --exclude '*' --always --dirty)"; git archive --format=tar.gz --prefix="$PREFIX/" -o "$PREFIX.tar.gz" HEAD)
Monitor consumed DDR bandwidth every seconds (Intel IMC HW counters)
LC_ALL=C perf stat $(perf list|awk '/uncore_imc.*(read|write)/{printf " -e %s", $1}') -a -B -I 1000 2>&1|stdbuf -oL awk '/#/{next}$1!=t{t=$1;if(s)print s;s=0}{s+=$2}'
Extract an ADB (Android) backup
dd if=<backup.adb> bs=1M skip=24 iflag=skip_bytes| pigz -dz | tar xv
Optimize JPEG for sharing
mogrify -auto-orient -define jpeg:dct-method=float -quality 75 -strip -interlace Plane -sampling-factor 4:2:0 -resize '1400x1400>' *.jpg