LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-22-2010, 04:30 AM   #1
CQ1ST
Member
 
Registered: Oct 2005
Location: NewZealand
Distribution: Xubuntu Trusty
Posts: 77

Rep: Reputation: 18
Question Copy folders + included mp3's in order


Hi, I'm asking again to (hopefully this time get an answer) (man I hope watael isn't around)

a little background: I've got a stupid mp3player, that doesn't order the media numerically/alphabetically but in the order the files are found on the disk... I've found out that most operating systems don't actually order these files either: they only display them this way to the user, this means that when I copy folders to my mp3player the order is all messed up... and I don't know "any" bash syntax, only cp,mv,rm,grep|apt-get etc
I've got all the folders I want copied to my player in one directory, and all the mp3s inside numbered 01,02..10,11..21,22..

Can you please [tell bash/cat/sed?/mkdir/cp to] make folders of the same names in the player, and then copy the mp3s 'in order' to the appropriate folders?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-22-2010, 05:06 AM   #2
mario.almeida
Member
 
Registered: May 2008
Location: India
Distribution: Ubuntu 10.04, CentOS, Manjaro
Posts: 179

Rep: Reputation: 27
Hi,

Your question is not clear to me, may be someone else can help you in this.

What I understand is this

you have a file 01xyz.mp3 or 01.mp3

And you want to create a directory by name 01xyz and copy 01xyz.mp3 to 01xyz directory or create a directory by name 01 and copy 01.mp3 to 01 directory

if so then try this.

Code:
#!/bin/bash

for f in $(ls *.mp3)
do
        dirName=${f%%.*}
        mkdir $dirName
        mv $f $dirName
done
 
Old 03-22-2010, 05:10 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Hi cq1st

I think I need a little further explanation?

Firstly, you do realise that the os and the file system are the ones that work out what is written where
and in what order and that it is simply the program you use for viewing things that actually displays the order
how you wish to perceive it??

Assuming you understand the above, what program are you using to view the file that you want in, i am guessing,
a numerically sorted order?
 
Old 03-22-2010, 06:50 AM   #4
CQ1ST
Member
 
Registered: Oct 2005
Location: NewZealand
Distribution: Xubuntu Trusty
Posts: 77

Original Poster
Rep: Reputation: 18
picture this:
you have 4 folders full of mp3s
you cp them all into your mp3players music folder (and they're all jumbled!)

manually i can:
mkdir /media/disk/MUSIC/folder over and over ,then
cp 01... 02... 03... "04 - clucks sake" /media/disk/MUSIC/folder1
over and over until all 4 folders are copied just right

ls,nautilus,windows explorer,cp (you name it, the files on your computer 'are not' sitting in order)
 
Old 03-22-2010, 07:32 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Ok ... I think I am catching on (I hope)
Tell me if this demo is what you are saying:

ACDC - highway_to_hell.mp3
- ride_on.mp3

Judas_Priest - ram_it_down.mp3
- johnny_b_goode.mp3

Now you cp all 4 mp3 files into mp3player_folder which looks like:

highway_to_hell.mp3
johnny_b_goode.mp3
ram_it_down.mp3
ride_on.mp3

But you would like to still be able to have them in say band order.

Am I on the right track??
 
Old 03-22-2010, 07:52 AM   #6
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
Try rsync command -- it sorts directories and files alphanumerically:

Code:
rsync -av /old/place /new/place
 
Old 03-22-2010, 07:53 PM   #7
CQ1ST
Member
 
Registered: Oct 2005
Location: NewZealand
Distribution: Xubuntu Trusty
Posts: 77

Original Poster
Rep: Reputation: 18
to show you what I mean: go into an album folder and type:
ls -t
(the time each file was written) and you see str8 away they are jumbled.
now:
rsync does not actually do it but this does
(I am so glad to finally find this as it saves me alot of time)
(the sort -z may not need the r after it, not sure just did it in test folders on my computer not the st00pid mp3player)

cd /MusicToMove
find . -print0 | sort -zr | xargs -0 cp --parents
--target-directory=/media/disk/MUSIC/FoldersMoved
 
Old 03-22-2010, 08:20 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
This problem exists because vfat is terrible file system.

After copying the files and *unmounting* the device, you can run fatsort on it (the device not the mount point). This command is packaged in debian under the same name, and therefore I guess it will be in Ubuntu too.

It think this may be the best solution, since it allows you to copy the files in any way you like.

Cheers,

Evo2.
 
2 members found this post helpful.
Old 12-24-2014, 12:42 AM   #9
CQ1ST
Member
 
Registered: Oct 2005
Location: NewZealand
Distribution: Xubuntu Trusty
Posts: 77

Original Poster
Rep: Reputation: 18
the -zr is definitely not needed (it's reverse! lol)

so it's
cd /MusicToMove
find . -print0 | sort -zh | xargs -0 cp --parents
--target-directory=/media/disk/MUSIC/FoldersMoved

(the -zh there is h for human readable alpha-numeric, it means 101-120 and the 201-220 with list perfectly)
 
Old 12-24-2014, 11:08 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Sheesh .. I know you kiwis can be a bit slow at times .... but 4 years (nearly 5)??
 
Old 12-24-2014, 01:44 PM   #11
CQ1ST
Member
 
Registered: Oct 2005
Location: NewZealand
Distribution: Xubuntu Trusty
Posts: 77

Original Poster
Rep: Reputation: 18
Bah Humbug! Sheesh you subscribed to this!?

it would be a whole lot more interesting if someone from a distro team or two were here saying "You know what we would be stupid not to add this simple functionality into every Linux distro out of the box from now (5 years ago?) on"
 
Old 12-24-2014, 01:59 PM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
It's not too late to correct post #2 for other people who might find this thread:

Code:
#!/bin/bash

for f in *.mp3
do
        dirName="$(dirname $f)"
        mkdir "$dirName"
        mv -- "$f" "$dirName"
done
This is much more robust.

See:

http://mywiki.wooledge.org/BashPitfa...8ls_.2A.mp3.29

Last edited by dugan; 12-24-2014 at 02:39 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cp will copy in any order, not alphanumeric DaveQB Linux - Software 3 01-10-2009 09:15 PM
mp3's created with kaudiocreator play in wrong order MartyJay Linux - Software 14 10-31-2008 06:08 AM
Order your copy now! ctt1wbw Ubuntu 2 01-10-2006 07:33 AM
File Order iwhen Burning MP3's W4LK Linux - General 1 06-29-2004 02:49 PM
how to copy public domain mp3's to hdd on rh 7.3 ergo_sum Linux - Newbie 6 11-15-2003 06:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration