LinuxQuestions.org
Review your favorite Linux distribution.
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 05-26-2008, 06:10 AM   #1
wizardhat
Member
 
Registered: Apr 2008
Location: Melbourne, Australia
Distribution: Slackware 12.2
Posts: 52
Blog Entries: 1

Rep: Reputation: 15
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?
 
Old 05-26-2008, 06:29 AM   #2
Takla
Member
 
Registered: Aug 2006
Distribution: Debian
Posts: 188

Rep: Reputation: 34
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.

Last edited by Takla; 05-26-2008 at 06:34 AM.
 
Old 05-26-2008, 06:33 AM   #3
Stéphane Ascoët
Member
 
Registered: Feb 2004
Location: Fleury-les-Aubrais, 120 km south of Paris
Distribution: Devuan, Debian, Mandrake, Freeduc (the one I used to work on), Slackware, MacOS X
Posts: 251

Rep: Reputation: 49
Thumbs down mp3 sucks

Just use a true hi-fi sound player... Or create a script that copies files in the numerical order.
 
0 members found this post helpful.
Old 05-26-2008, 06:52 AM   #4
Takla
Member
 
Registered: Aug 2006
Distribution: Debian
Posts: 188

Rep: Reputation: 34
Quote:
Originally Posted by Stéphane Ascoët View Post
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.
 
Old 05-29-2008, 03:47 AM   #5
wizardhat
Member
 
Registered: Apr 2008
Location: Melbourne, Australia
Distribution: Slackware 12.2
Posts: 52

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Quote:
Originally Posted by Stéphane Ascoët View Post
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
 
Old 03-23-2010, 06:31 PM   #6
CQ1ST
Member
 
Registered: Oct 2005
Location: NewZealand
Distribution: Xubuntu Trusty
Posts: 77

Rep: Reputation: 18
..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
 
2 members found this post helpful.
Old 11-24-2010, 08:10 AM   #7
crramirez
LQ Newbie
 
Registered: Nov 2010
Distribution: opensuse
Posts: 1

Rep: Reputation: 0
Thank you very much. I used it without the -r option. Works great!!
 
Old 05-10-2012, 01:03 AM   #8
mikeklimczak
LQ Newbie
 
Registered: May 2012
Posts: 2

Rep: Reputation: Disabled
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.
 
Old 05-10-2012, 05:48 PM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Another possible solution for people having this problem is fatsort.

http://fatsort.sourceforge.net/
 
1 members found this post helpful.
Old 05-23-2012, 12:38 AM   #10
CQ1ST
Member
 
Registered: Oct 2005
Location: NewZealand
Distribution: Xubuntu Trusty
Posts: 77

Rep: Reputation: 18
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"
 
Old 04-04-2020, 03:22 PM   #11
mh4it
LQ Newbie
 
Registered: Apr 2020
Posts: 3

Rep: Reputation: Disabled
Quote:
Originally Posted by CQ1ST View Post
..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?
 
Old 04-05-2020, 02:53 AM   #12
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by mh4it View Post
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.
 
  


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
Command to copy files/folders but skip bad/corrupt files?? leemoreau Linux - Newbie 2 04-02-2007 02:27 PM
Order files by last modifed Madone_SL_5.5 Linux - Newbie 1 12-13-2006 06:43 PM
Arranging Files In Alphabetical order swatward Linux - General 4 12-11-2006 08:14 PM
Order your copy now! ctt1wbw Ubuntu 2 01-10-2006 07:33 AM
what files must i edit in order to: fazaman Debian 1 02-23-2005 08:33 AM

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

All times are GMT -5. The time now is 11:42 AM.

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