CLI Fu: Difference between revisions

From Traxel Wiki
Jump to navigation Jump to search
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Hacking]]
[[Category:Hacking]]
= Image Magick =
Convert, noclobber:
<pre>ls webp/*webp | sed 's/webp//g' | awk '{print "[ -f png"$1"png ] || convert webp"$1"webp png"$1"png"}'</pre>
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>
= Awk =
= Awk =
Using Awk for sums:
Using Awk for sums:
Line 11: Line 5:
<pre>ls -l | awk '{sum += $5} END {print sum}'</pre>
<pre>ls -l | awk '{sum += $5} END {print sum}'</pre>


= Backup Audio CDs =
= Audio CDs =
== Backup Backup ==
== Backup Backup ==
<pre>
<pre>
cd /media/bob
rsync -navz --size-only --delete /media/bob/Seagate\ Backup\ Plus\ Drive/Media/ /media/bob/Seagate\ Portable\ Drive/Media/
rsync -avz --size-only --delete Seagate\ Backup\ Plus\ Drive/Media/ Seagate\ Portable\ Drive/Media/
</pre>
</pre>
remove -n for live fire


== Store Image ==
== Store Image ==
Line 85: Line 79:
done
done
rm *.wav
rm *.wav
</pre>
= DVD Handling =
== Resetting a USB DVD Drive in Linux ==
If your USB DVD drive becomes unresponsive in Linux, you can attempt to reset it without rebooting your system by following these steps:
=== Identify the USB Device ===
Use the <code>lsusb</code> command to list all USB devices and find your DVD drive:
<pre>
lsusb
</pre>
<pre>
Bus 002 Device 005: ID 152d:0562 JMicron Technology Corp. / JMicron USA Technology Corp. JMS567 SATA 6Gb/s bridge
</pre>
=== Check the Device Status ===
Use <code>dmesg</code> or look at <code>/var/log/syslog</code> or <code>/var/log/messages</code> for any specific issues.
=== USB Device Reset ===
Reset the USB device by echoing a special value to the <code>/sys</code> directory:
<pre>
echo 0 | sudo tee /sys/bus/usb/devices/usb[Bus]/[Bus]-[Device]/authorized
echo 1 | sudo tee /sys/bus/usb/devices/usb[Bus]/[Bus]-[Device]/authorized
</pre>
Replace <code>[Bus]</code> and <code>[Device]</code> with the appropriate numbers from the <code>lsusb</code> output.
=== Unloading and Reloading the Kernel Module ===
If you know the kernel module for your USB drive, unload it:
<pre>
sudo rmmod uhci_hcd
</pre>
And reload it:
<pre>
sudo modprobe uhci_hcd
</pre>
=== Restarting the udev Service ===
Restart the <code>udev</code> service, which manages device nodes:
<pre>
sudo service udev restart
</pre>
=== Using usbreset ===
Compile and use the <code>usbreset</code> program for a more convenient reset.
'''Note:''' Replace <code>uhci_hcd</code> with the module specific to your system. Always ensure no process is using the device before attempting a reset.
'''Caution:''' Resetting kernel modules and USB devices can lead to an unstable system state. Use these commands carefully and ensure you're not affecting other essential USB devices.
If these methods do not resolve the issue, the problem may lie with the hardware of the drive, USB port, or cable. Consider trying a different port or cable.
= Portable Drives =
<pre>
lsblk
udisksctl mount -b /dev/sdb1
udisksctl unmount -b /dev/sdb1
</pre>
= Image Magick =
Convert, noclobber:
<pre>ls webp/*webp | sed 's/webp//g' | awk '{print "[ -f png"$1"png ] || convert webp"$1"webp png"$1"png"}'</pre>
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>
= Math =
<pre>ADD=$(( 1 + 2 ))</pre>
= systemctl =
<pre>
systemctl list-units --type=service --all | grep active| grep -v inactive
</pre>
</pre>

Latest revision as of 20:31, 5 September 2024

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:

  1. Split the raw BIN audio file into individual tracks using the CUE sheet.
  2. 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

DVD Handling

Resetting a USB DVD Drive in Linux

If your USB DVD drive becomes unresponsive in Linux, you can attempt to reset it without rebooting your system by following these steps:

Identify the USB Device

Use the lsusb command to list all USB devices and find your DVD drive:

lsusb
Bus 002 Device 005: ID 152d:0562 JMicron Technology Corp. / JMicron USA Technology Corp. JMS567 SATA 6Gb/s bridge

Check the Device Status

Use dmesg or look at /var/log/syslog or /var/log/messages for any specific issues.

USB Device Reset

Reset the USB device by echoing a special value to the /sys directory:

echo 0 | sudo tee /sys/bus/usb/devices/usb[Bus]/[Bus]-[Device]/authorized
echo 1 | sudo tee /sys/bus/usb/devices/usb[Bus]/[Bus]-[Device]/authorized

Replace [Bus] and [Device] with the appropriate numbers from the lsusb output.

Unloading and Reloading the Kernel Module

If you know the kernel module for your USB drive, unload it:

sudo rmmod uhci_hcd

And reload it:

sudo modprobe uhci_hcd

Restarting the udev Service

Restart the udev service, which manages device nodes:

sudo service udev restart

Using usbreset

Compile and use the usbreset program for a more convenient reset.

Note: Replace uhci_hcd with the module specific to your system. Always ensure no process is using the device before attempting a reset.

Caution: Resetting kernel modules and USB devices can lead to an unstable system state. Use these commands carefully and ensure you're not affecting other essential USB devices.

If these methods do not resolve the issue, the problem may lie with the hardware of the drive, USB port, or cable. Consider trying a different port or cable.

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