CLI Fu: Difference between revisions
(17 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Hacking]] | [[Category:Hacking]] | ||
= Awk = | |||
Using Awk for sums: | |||
<pre>ls -l | awk '{print $5}' | awk '{sum += $1} END {print sum}'</pre> | |||
<pre>ls -l | awk '{sum += $5} END {print sum}'</pre> | |||
= Audio CDs = | |||
== Backup Backup == | |||
<pre> | |||
rsync -navz --size-only --delete /media/bob/Seagate\ Backup\ Plus\ Drive/Media/ /media/bob/Seagate\ Portable\ Drive/Media/ | |||
</pre> | |||
remove -n for live fire | |||
== Store Image == | |||
<pre> | |||
cdrdao read-cd --read-raw --driver generic-mmc:0x20000 --datafile cdimage.bin cdimage.toc && toc2cue cdimage.toc cdimage.cue | |||
</pre> | |||
<pre> | |||
cdrdao read-cd --read-raw --datafile audiocd.bin --device /dev/cdrom --driver generic-mmc-raw audiocd.cue | |||
</pre> | |||
== Convert BIN/CUE to Ogg Format == | |||
To convert a `audiocd.bin` and `audiocd.cue` file to Ogg format, you'll need to follow a two-step process: | |||
# '''Split''' the raw BIN audio file into individual tracks using the CUE sheet. | |||
# '''Convert''' the individual tracks to Ogg format. | |||
Here's a step-by-step guide: | |||
=== 1. Install Necessary Tools: === | |||
Depending on your distribution, you'll need to install some tools. For the purpose of this guide, we'll use `cuetools` and `shntool` for splitting, and `ffmpeg` for conversion. | |||
* '''Debian/Ubuntu:''' | |||
<source lang="bash"> | |||
sudo apt-get install cuetools shntool ffmpeg vorbis-tools | |||
</source> | |||
* '''Fedora:''' | |||
<source lang="bash"> | |||
sudo dnf install cuetools shntool ffmpeg vorbis-tools | |||
</source> | |||
=== 2. Split the BIN File into Individual Tracks: === | |||
Navigate to the directory containing your `.cue` and `.bin` files and run: | |||
<source lang="bash"> | |||
shnsplit -f audiocd.cue -t "%n-%t" -o wav audiocd.bin | |||
</source> | |||
This will produce WAV files named like `01-Trackname.wav`, `02-Trackname.wav`, etc. | |||
=== 3. Convert WAV Files to Ogg Format: === | |||
<source lang="bash"> | |||
for file in *.wav; do | |||
ffmpeg -i "$file" "${file%.wav}.ogg" | |||
done | |||
</source> | |||
This script will iterate over each WAV file and convert it to Ogg using `ffmpeg`. The resulting files will have the same base name as the original WAV files but with an `.ogg` extension. | |||
=== 4. Clean Up (Optional): === | |||
If you're satisfied with the Ogg files and no longer need the WAV files, you can delete them: | |||
<source lang="bash"> | |||
rm *.wav | |||
</source> | |||
You should now have individual Ogg tracks extracted from your audio CD BIN/CUE image. | |||
=== Summary === | |||
<pre> | |||
shnsplit -f audiocd.cue -t "%n-%t" -o wav audiocd.bin | |||
for file in *.wav; do | |||
ffmpeg -i "$file" "${file%.wav}.ogg" | |||
done | |||
rm *.wav | |||
</pre> | |||
= FFMpeg = | |||
* <pre>ffmpeg -i audiobook.m4b -acodec libmp3lame audiobook.mp3</pre> | |||
= Portable Drives = | |||
<pre> | |||
lsblk | |||
udisksctl mount -b /dev/sdb1 | |||
udisksctl unmount -b /dev/sdb1 | |||
</pre> | |||
= Image Magick = | = Image Magick = | ||
Convert, noclobber: | Convert, noclobber: | ||
Line 6: | Line 96: | ||
Convert, noclobber, thumbnail: | Convert, noclobber, thumbnail: | ||
<pre>ls png/*png | sed 's/png//g' | awk '{print "[ -f jpg"$1"jpg ] || convert -thumbnail 256x256 png"$1"png jpg"$1"jpg"}'</pre> | <pre>ls png/*png | sed 's/png//g' | awk '{print "[ -f jpg"$1"jpg ] || convert -thumbnail 256x256 png"$1"png jpg"$1"jpg"}'</pre> | ||
= Math = | |||
<pre>ADD=$(( 1 + 2 ))</pre> | |||
= systemctl = | |||
<pre> | |||
systemctl list-units --type=service --all | grep active| grep -v inactive | |||
</pre> |
Latest revision as of 17:41, 9 March 2025
Awk
Using Awk for sums:
ls -l | awk '{print $5}' | awk '{sum += $1} END {print sum}'
ls -l | awk '{sum += $5} END {print sum}'
Audio CDs
Backup Backup
rsync -navz --size-only --delete /media/bob/Seagate\ Backup\ Plus\ Drive/Media/ /media/bob/Seagate\ Portable\ Drive/Media/
remove -n for live fire
Store Image
cdrdao read-cd --read-raw --driver generic-mmc:0x20000 --datafile cdimage.bin cdimage.toc && toc2cue cdimage.toc cdimage.cue
cdrdao read-cd --read-raw --datafile audiocd.bin --device /dev/cdrom --driver generic-mmc-raw audiocd.cue
Convert BIN/CUE to Ogg Format
To convert a `audiocd.bin` and `audiocd.cue` file to Ogg format, you'll need to follow a two-step process:
- Split the raw BIN audio file into individual tracks using the CUE sheet.
- Convert the individual tracks to Ogg format.
Here's a step-by-step guide:
1. Install Necessary Tools:
Depending on your distribution, you'll need to install some tools. For the purpose of this guide, we'll use `cuetools` and `shntool` for splitting, and `ffmpeg` for conversion.
- Debian/Ubuntu:
sudo apt-get install cuetools shntool ffmpeg vorbis-tools
- Fedora:
sudo dnf install cuetools shntool ffmpeg vorbis-tools
2. Split the BIN File into Individual Tracks:
Navigate to the directory containing your `.cue` and `.bin` files and run:
shnsplit -f audiocd.cue -t "%n-%t" -o wav audiocd.bin
This will produce WAV files named like `01-Trackname.wav`, `02-Trackname.wav`, etc.
3. Convert WAV Files to Ogg Format:
for file in *.wav; do
ffmpeg -i "$file" "${file%.wav}.ogg"
done
This script will iterate over each WAV file and convert it to Ogg using `ffmpeg`. The resulting files will have the same base name as the original WAV files but with an `.ogg` extension.
4. Clean Up (Optional):
If you're satisfied with the Ogg files and no longer need the WAV files, you can delete them:
rm *.wav
You should now have individual Ogg tracks extracted from your audio CD BIN/CUE image.
Summary
shnsplit -f audiocd.cue -t "%n-%t" -o wav audiocd.bin for file in *.wav; do ffmpeg -i "$file" "${file%.wav}.ogg" done rm *.wav
FFMpeg
ffmpeg -i audiobook.m4b -acodec libmp3lame audiobook.mp3
Portable Drives
lsblk udisksctl mount -b /dev/sdb1 udisksctl unmount -b /dev/sdb1
Image Magick
Convert, noclobber:
ls webp/*webp | sed 's/webp//g' | awk '{print "[ -f png"$1"png ] || convert webp"$1"webp png"$1"png"}'
Convert, noclobber, thumbnail:
ls png/*png | sed 's/png//g' | awk '{print "[ -f jpg"$1"jpg ] || convert -thumbnail 256x256 png"$1"png jpg"$1"jpg"}'
Math
ADD=$(( 1 + 2 ))
systemctl
systemctl list-units --type=service --all | grep active| grep -v inactive