Search This Blog

2025/02/26

Bash script to collect .mp3 files from album folder to Music folder directly

Suppose you have two folders /home/sangram/Music & /home/sangram/Music/Other,
In Music Folder you only want to keep mp3 files directly.The Other folder 
contain multiple folders each containing mp3 files for different Song Album.
 
Here instead of directly copying mp3 to 'Music' folder i created another folder
in 'Music' folder to collect all such files named 'AllSongs'. 
 
Then following script will copy all mp3 files from Album folders to mp3.It does
not implement nested folder scenario.Code is Bash Script that can be run as
 
Assume code file name is OrganizeMusicFiles.sh then you need to base folder of
it to make it executable run
chmod +x OrganizeMusicFiles.sh

Then run script as follows  
./OrganizeMusicFiles.sh
 
 
Code: 
 
/bin/bash 
search_dir=/home/sangram/Music/Other
dest_dir=/home/sangram/Music/AllSongs/
echo "Search Directory: $search_dir"
echo "Destination Directory: $dest_dir"
echo "--------------------------------"

touch CopyLog.psv
echo "source|destinaion|time" > CopyLog.psv;

counter=0
break_flag=0
for entry in "$search_dir"/*; do
echo "--------------Folder:$entry------------------"
for inner_entry in "$entry"/*; do
echo "File under consideration is: $inner_entry"

#get file extension
filename=$(basename -- "$inner_entry")
extension="${filename##*.}"
echo "File Extension: $extension"
desired_extensions=("mp3")

if [[ ${desired_extensions[@]} =~ $extension ]]
then
echo "File $inner_entry is mp3"
else
echo "File $inner_entry is not mp3"
continue
fi

echo "Coping File:'$inner_entry' To '$dest_dir'"
echo "cp '$inner_entry' '$dest_dir'"

#logging the copy operation
current_date_time="`date +%Y%m%d%H%M%S`";
echo "'$inner_entry'|'$dest_dir'|'$current_date_time'" >> CopyLog.psv;
echo "\n" >> CopyLog.psv;

cp "$inner_entry" '$dest_dir'
counter=$((counter+1))

#coping only 10 files
if [ $counter -eq 10 ]
then
$break_flag=1
break
fi

echo '--------------------------------'


done
#if inner loop is broken then break outer loop also broken
if [ $break_flag -eq 1 ]
then
break
fi
echo "Total Files Copied: $counter"
break
done
 
I think the code might useful for someone which trying to something similar 
for sake of fun.
 
Happy Coding !
 
 

2025/02/25

How to create bootable USB stick from iso file in Debian GNU/Linux 12 ?

Download ISO file from your preferred distro if that burn on CD/DVD then system can boot
from this CD/DVD.

   I am downloading latest version of Ubuntu from Office Website.

DOWNLOAD URL:https://mirrors.utkarsh2102.org/ubuntu-releases/24.10
             /ubuntu-24.10-desktop-amd64.iso
   	
I found out that downloading from torrent is better else you need to use Download Manager 
Application to avoid interruption in network connection.
   
Path to downloaded ISO
  Find path to downloaded ISO.In my case the path is
	
       	/home/sangram/Downloads/ubuntu-24.10-desktop-amd64.iso
   
Then Find path to your Flash Drive.
	root@debian:/home/sangram/Downloads# blkid
	/dev/sdb4: UUID="4bec5b9b-0399-4625-888e-1f3c7879a2d2" BLOCK_SIZE="4096" 
                        TYPE="ext4" PARTUUID="709020f5-3615-48ae-945e-7aaf90e1c224"
	/dev/sdb2: LABEL="Windows10Extra" BLOCK_SIZE="512" UUID="8E80C8B780C8A6D5" 
                        TYPE="ntfs" PARTUUID="2e556718-1bca-45e6-a8e1-da6176028372"
	/dev/sdb3: UUID="998967c0-01bb-435c-be51-5111ac2f42dd" 
                        TYPE="swap" PARTUUID="7f3e46bb-d429-4255-85b6-d574874b0441"
	/dev/sdb1: LABEL="UbuntuExtra" UUID="32d124b4-f63e-4db8-9862-2bd1ccce96d9" 
                        BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="022273ff-1744-4ddf-918b-454356e51fae"
	/dev/sr0: BLOCK_SIZE="2048" UUID="2002-12-25-13-26-43-00" 
                        LABEL="021225_1321" TYPE="iso9660"
	/dev/sda4: UUID="f2138513-5e98-4fc3-a41d-a43a68a9239b" 
                        BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="869e87f7-04"
	/dev/sda2: BLOCK_SIZE="512" UUID="FA0A69290A68E3DB" TYPE="ntfs" 
                        PARTUUID="869e87f7-02"
	/dev/sda3: BLOCK_SIZE="512" UUID="1EAEDC1BAEDBE973" TYPE="ntfs" 
                        PARTUUID="869e87f7-03"
	/dev/sda1: LABEL="System Reserved" BLOCK_SIZE="512" UUID="201667091666DF72" 
                        TYPE="ntfs" PARTUUID="869e87f7-01"
	/dev/sdc: UUID="C471-F788" BLOCK_SIZE="512" TYPE="vfat"

Here /dev/sdc is my Flash USB Drive on which I want to install Bootable Ubuntu.

Command Format:
	sudo dd if=[path_to_iso] of=[path_to_usb]

Actual command in our case will look like

	sudo dd  bs=4M if=/home/sangram/Downloads/ubuntu-24.10-desktop-amd64.iso 
                       of=/dev/sdc  status=progress oflag=sync