LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I get cp to copy files in the right order? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-get-cp-to-copy-files-in-the-right-order-644818/)

wizardhat 05-26-2008 06:10 AM

How do I get cp to copy files in the right order?
 
Hey all,

I've got an mp3 player that stores files in the order that they are written. Unfortunately, when I copy a directory to my mp3 player, it copies the files in a seemingly random order (I say "seemingly" because running the same cp command again copies them in the same strange order). My problem is that, you guessed it, this screws up the play order.

Is there any way around this, barring copying everything one by one (by hand, which gets tedious)?


Here's an example of what I'm talking about:

Quote:

$ cp -rv /mnt/hd/mp3/Warren\ Zevon/Learning\ To\ Flinch/ .
`/mnt/hd/mp3/Warren Zevon/Learning To Flinch/' -> `./Learning To Flinch'
`/mnt/hd/mp3/Warren Zevon/Learning To Flinch/06-The French Inhaler.mp3' -> `./Learning To Flinch/06-The French Inhaler.mp3'
`/mnt/hd/mp3/Warren Zevon/Learning To Flinch/02-Lawyers, Guns & Money.mp3' -> `./Learning To Flinch/02-Lawyers, Guns & Money.mp3'
`/mnt/hd/mp3/Warren Zevon/Learning To Flinch/12-Jungle Work.mp3' -> `./Learning To Flinch/12-Jungle Work.mp3'
`/mnt/hd/mp3/Warren Zevon/Learning To Flinch/01-Splendid Isolation.mp3' -> `./Learning To Flinch/01-Splendid Isolation.mp3'
`/mnt/hd/mp3/Warren Zevon/Learning To Flinch/03-Mr. Bad Example.mp3' -> `./Learning To Flinch/03-Mr. Bad Example.mp3'
`/mnt/hd/mp3/Warren Zevon/Learning To Flinch/13-Piano Fighter.mp3' -> `./Learning To Flinch/13-Piano Fighter.mp3'

etc etc etc
This was just ripped from a cd in sequential order, so I'm not sure why it's coming out like that. Can anyone help me out here?

Takla 05-26-2008 06:29 AM

The problem isn't the cp command, it's the firmware and FAT filesystem on your mp3 player. It can only display the files in the order written to disk (you can see the same behaviour on older flash drives). If you transcode a folder of music on your PC and look at your encoder's output in the terminal you'll see that the files are not in alphanumeric order and are dealt with one by one in the order that they physically lie on the disk. Fortunately the OS filemanager and command line utilities by default display everything ordered nicely in the way we like.

An easy workaround is to first create a folder on the mp3player like "Warren Zevon - Learning to Flinch" and then copy the music files from the PC into that folder using your file manager. They should now appear on your mp3 player sorted alphanumericaly. This works for me on my cheap cheap chinese mp3 player using emelfm2 file manager.

Stéphane Ascoët 05-26-2008 06:33 AM

mp3 sucks
 
Just use a true hi-fi sound player... Or create a script that copies files in the numerical order.

Takla 05-26-2008 06:52 AM

Quote:

Originally Posted by Stéphane Ascoët (Post 3164848)
Just use a true hi-fi sound player... Or create a script that copies files in the numerical order.

OP's question has nothing to do with the mp3 format sucking or not sucking.

wizardhat 05-29-2008 03:47 AM

Quote:

Originally Posted by Stéphane Ascoët (Post 3164848)
Or create a script that copies files in the numerical order.

I'd do this, but I wouldn't know where to start. Hence the post in the newbie forum :)

CQ1ST 03-23-2010 06:31 PM

..the answer is:
ls -t
(shows the problem)
cd MusicToMove/
find . -print0 | sort -zr | xargs -0 cp --parents
--target-directory=/media/disk/MUSIC/FoldersMoved
(fixes the problem)

..in sort -zr ,the r may be optional ,I've tested this on computer ,not an mp3player

crramirez 11-24-2010 08:10 AM

Thank you very much. I used it without the -r option. Works great!!

mikeklimczak 05-10-2012 01:03 AM

I know this thread is bit old now, but we had a similar frustration. We copy large amounts of data using the "cp -Rv" command and it's annoying that the copy is not completed alphabetically because if it was we could tell at a glance how far through the copy the job was. We instead use "rsync -av" now and the copy is much easier to monitor.

We have a full description of the solution on our offsite backup website here.

David the H. 05-10-2012 05:48 PM

Another possible solution for people having this problem is fatsort.

http://fatsort.sourceforge.net/

CQ1ST 05-23-2012 12:38 AM

Thank you Mike for your post/answer.

I'd love to see the gui use this rsync -avP by default [someday] as it's infuriating to find this flaw (in both windows and linux) is the standard behaviour when solutions are (and have been for some time) available.

I saw later that month, that the windows xp computers at (one of) my local library copied all files alphabetically, and remember thinking "what a clever techie, sorting this .. as [any] tech 'would' when copying albums/songs was a feature used often by his/her patrons"

mh4it 04-04-2020 03:22 PM

Quote:

Originally Posted by CQ1ST (Post 3909705)
..the answer is:
ls -t
(shows the problem)
cd MusicToMove/
find . -print0 | sort -zr | xargs -0 cp --parents
--target-directory=/media/disk/MUSIC/FoldersMoved
(fixes the problem)

..in sort -zr ,the r may be optional ,I've tested this on computer ,not an mp3player

This was great help to me! My mp3s are sorted alphabetically rather than by date of simultaneous copy. Is there anyway to reverse the descending order to ascending?

Turbocapitalist 04-05-2020 02:53 AM

Quote:

Originally Posted by mh4it (Post 6107826)
This was great help to me! My mp3s are sorted alphabetically rather than by date of simultaneous copy. Is there anyway to reverse the descending order to ascending?

Take a look at the sort utility and whether or not you want the -r option. If you have questions about that please do ask as many as you have, but in a new thread. It is best to start a new thread insted of continuing one so old like this one.


All times are GMT -5. The time now is 11:50 PM.