Basically I am writing this to transfer all .mp3
files to my mobile through Bluetooth
option. If I am directly coping it to SD Card
, it is not working. My button phone not recognizing the MP3 files which I've copied it from my computer.
IF, somehow I can copy the MP3 files into a single folder, I can easily transfer all my files into my phone by selecting all files with + option in Bluetooth file transfer
.
I had a backup script written once by myself that you can find that it here.
#!/usr/bin/bash
#------------backupscript--------------
#mkdir ~/backup/`date +%d-%m-%Y`
#for i in `ls ~/repos`
#do
#cp -r ~/repos/`echo $i` ~/backup/`date +%d-%m-%Y`/`echo $i` #recursively copies the folder
#done
#------------backupscript--------------
This I have written to take a backup of my svn repos
To list the .mp3 files I found the following command from internet, like,
for i in `find . -name *.mp3 -exec echo {} ;`
from the link, - How can I do foreach *.mp3 file recursively in a bash script?
Based on that I've altered my shell backup script which I've written like,
for i in `find . -name *.mp3 -exec echo {} \;`
do
cp `echo $i` ./oneList/
done
it works for me coping my all mp3 files into, but I am getting errors like I have put in the below stanza,
cp: cannot stat 'Jeevan': No such file or directory cp: cannot stat '(sad).mp3': No such file or directory cp: cannot stat './585/Geethanjali/Oru': No such file or directory cp: cannot stat 'Jeevan.mp3': No such file or directory cp: cannot stat './585/Geethanjali/Otha': No such file or directory cp: cannot stat 'Ruba.mp3': No such file or directory
Later I found discrepancies in the no. of files.
What I am doing wrong over here coping mp3 files into single folder using the bash script which I am writing.
What I have to alter in my script.
If you've got a non-ancient version of Bash you don't need to use find
. Try this Shellcheck-clean code:
#! /bin/bash -p
shopt -s dotglob globstar nullglob
for mp3file in **/*.mp3; do
cp -v -- "$mp3file" oneList/
done
shopt -s ...
enables some Bash settings that are required by the code:
dotglob
enables globs to match files and directories that begin with .
. find
processes such files by default.globstar
enables the use of **
to match paths recursively through directory trees. This option was introduced with Bash 4.0 (released in 2009) but it is dangerous to use in versions before 4.3 (released in 2014) because it follows symlinks.nullglob
makes globs expand to nothing when nothing matches (otherwise they expand to the glob pattern itself, which is almost never useful in programs).--
and quotes in the cp
command.-v
("verbose") option is not supported by all versions of cp
.