The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    get linux to copy files to a removable disk in alphabetical order

    Discussion in 'Linux Compatibility and Software' started by Fittersman, Jun 13, 2008.

  1. Fittersman

    Fittersman Wanna trade?

    Reputations:
    225
    Messages:
    1,306
    Likes Received:
    0
    Trophy Points:
    55
    my car deck browses the files on a removable disk in the order they were copied to the removable disk instead of in alphabetical order. I *think* linux copies files to removable disks based on size and not in alphabetical order. Is there anyway to force it to copy in alphabetical order instead so they are in a usable order when i try to play the songs in my car?
     
  2. trwrt

    trwrt Notebook Consultant

    Reputations:
    39
    Messages:
    183
    Likes Received:
    0
    Trophy Points:
    30
    Assuming you're using bash, something like:

    for i in `ls *.mpg`; do cp $i /path/to/disk/; done

    should work.
     
  3. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    I'd add a 'sync' command after the cp in that loop to ensure that the linux disk buffers are flushed before copying the next file.

    Code:
    for i in `ls *.mp3`; do cp "$i" /path/to/disk/;sync; done
    My first MP3 flash player was a MuVo and it had that brain-dead system of playing the tracks in directory order - I think someone wrote a little Windows utility to sort the directory into alphabetically order, but I don't think anyone wrote a similiar linux utility, and the bash shell script worked fine.
     
  4. Fittersman

    Fittersman Wanna trade?

    Reputations:
    225
    Messages:
    1,306
    Likes Received:
    0
    Trophy Points:
    55
    ive got windows also, any idea what that was called?

    and ill try those command line options when i get a chance
     
  5. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    I had to look for it on a backup of an old D: drive that I saved many years ago, it was called FATSort.
     
  6. jas

    jas Notebook Evangelist

    Reputations:
    697
    Messages:
    622
    Likes Received:
    5
    Trophy Points:
    31
    And it's even still out there, and proposed for solving the problem of the OP...

    Good Luck..
     
  7. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    Flushing the buffers between files does not add anything and is in fact going to make things slower.

    Flushing the buffers before removing the device is a good idea but if you unmount (which you always should) then you're fine.
     
  8. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    Ah, same name, but not the same program - as the one that I knew of was a M$ Windoze only program.

    The linux one appears to be by a different author, it's available in the Debian Etch repository, and probably in one of Ubuntu repositories.
     
  9. jas

    jas Notebook Evangelist

    Reputations:
    697
    Messages:
    622
    Likes Received:
    5
    Trophy Points:
    31
    Sorry. Here's the Windows one. (Or A Windows one..)

    Good Luck..
     
  10. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    I would guess that you've never come across one of these very badly designed mp3 players?

    The sync is necessary to ensure that the FAT directory entries are written in the correct order. What I found is that if I didn't use the sync command after each track is copied then occasionally two tracks would be in the wrong order.

    BTW I am talking about a very specialised case with a minority of mp3 players, so please lemur don't take this as dumping on your message, as what you say would apply most of the time.
     
  11. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    jas, no problem, we are in a linux forum - and I wasn't aware of the linux program.
     
  12. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    [Edit: well, I just saw timberwolf's edit so I guess we agree that in general sync is not usually needed. Good!]

    Most mp3 players that I've dealt with were either good enough to play mp3s in some sort of logical order independently of the order of copy or were devices which needed a specific order. For the latter only the order of the copies matters. These devices are lacking in the human interface department but technically that behavior is not a bug.

    Let's say you mount an external drive on /mnt and you do this:

    Code:
    cp A /mnt/
    cp B /mnt/
    
    All the blocks which will ever be allocated to A and the directory entry are already decided and set before the first cp ends. This is true even if the copy of A which will be on the external disk is still only existing in memory buffers by the time the first cp ends. There is no way in which the subsequent copy of B can alter this in any way. Adding a sync between the two cp commands changes nothing.

    Things get more complicated with journaling file systems depending on what is journaled precisely but we're talking about fat here.

    This being said, yeah, there may be devices out there which are buggy. Or even drivers which are buggy. I've had to deal with buggy USB drivers in Linux before (maybe 2 years ago): I had to go through hoops to get them to behave properly. (Like mount the drive with special flags or unload high-speed USB modules from memory before using those devices.) Devices which really need "sync" between copies are not just badly designed but are buggy.

    These buggy devices are not the norm.
     
  13. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    We agree.

    Off on a tangent, I'm on the look out for a new mp3 player, that is linux friendly, because my Trekstor Vibez mp3 players hard drive has just begun to fail :( The Cowan iAudio 7 16GB Flash player looks interesting but according to the reviews doesn't have the same sound quality as my current player.
     
  14. srunni

    srunni Notebook Deity

    Reputations:
    96
    Messages:
    854
    Likes Received:
    0
    Trophy Points:
    30
    Check out the Creative Zen: http://www.newegg.com/Product/Product.aspx?Item=N82E16855102041&Tpk=Creative

    That's the 32GB version, but you can also get it in 16, 8 and 4 GB. It's got great sound quality, and works with Amarok or Gnomad2. I bought it a few weeks back to replace my dying iPod Photo, and it's got amazing sound quality.
     
  15. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    I've had to copy files back and forth between various devices but none of them belonged to me. I got my wife a Cowon D2 for her birthday last year. She used it mainly with Windows but I also used it with Linux without problem. The sound quality seems fine but I can't compare with other devices. One great thing about this device though is the battery life. We used it on a 12 hour drive from DC to Montreal and then 12 hours back without having to recharge it.

    Oh, and I avoid Creative. My reason to avoid them is ideological. There was a flap with Creative going after a guy who modded some of their drivers:

    http://digg.com/mods/Creative_Goes_After_Driver_Modder

    I really don't care whether Creative had a legal right to go after the modder. The fact is that Creative was providing drivers which crippled the capabilities of their hardware on purpose. The guy modded the drivers to uncripple the hardware. Creative went after him. Not cool. Creative eventually backed off but I'm still not trusting them.
     
  16. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    I have to admit that I've not liked Creative mp3 players in the past, but I've forgotten the reasons why.
    A short list of my pros and cons for the Creative ZEN
    Pros:
    large flash memory size.
    sound quality.
    Cons:
    Requires an application to transfer tracks.
    Limited file formats (i.e. no Vorbis ogg).
    Multimedia player.

    I'm not sure if it does gapless playback, sadly very few players have the feature, and even fewer do it properly.

    Lemur, a good reason not buy Creative.
     
  17. Fittersman

    Fittersman Wanna trade?

    Reputations:
    225
    Messages:
    1,306
    Likes Received:
    0
    Trophy Points:
    55
    when i tried fatsort, here was the output: (where FEDORA is the name of my usb drive)

    Code:
    cleippi@Christopher-PC:~/Music$ fatsort /media/FEDORA/
    FATSort Utility 0.9.8.2 by Boris Leidner <fatsort(at)formenos.de>
    
    check_mounted: Unable to get realpath!
    sort_fs: Could not check if filesystem is mounted!
    main: Failed to sort file system!
    cleippi@Christopher-PC:~/Music$
    
    when i tried the command line here is what happened: (keep in mind my music is sorted into folders with the artist name as the folder)

    Code:
    cleippi@Christopher-PC:~/Music$ for i in `ls`; do cp $i /media/disk/; done
    cp: cannot stat `30': No such file or directory
    cp: cannot stat `Seconds': No such file or directory
    cp: cannot stat `From': No such file or directory
    cp: cannot stat `Mars': No such file or directory
    
     
  18. Patrick

    Patrick Formerly beat spamers with stiks

    Reputations:
    2,284
    Messages:
    2,383
    Likes Received:
    93
    Trophy Points:
    66
    The command line is tripping out over spaces.
     
  19. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    Probably putting double quotes around $i in the original for loop would be enough:

    Code:
    for i in `ls`; do cp "$i" /media/disk/; done
    
    For any sizeable job, I prefer to use find with -print0 and then use xargs with the -0 flag. Theoretical example:

    Code:
    $ cd ~/Music/
    $ find . -type f -print0 | xargs -0 -iXX cp XX /media/blah/
    
    This does not trip over spaces. But as I typed it above there are other problems like the fact that find will traverse your entire Music directory and subdirectories but "cp" does not create directories on the destination. This is fixable by giving find a -maxdepth argument or by doing the work in two passes: one to create the directory structure on the destination and one to copy the files. I'm pressed for time right now so the exercise is left to the reader. Man is your friend. (Man as in the command "man"... before people think I'm suggesting something philosophical.)
     
  20. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    Given what fatsort is meant to do, I would think that the filesystem should be umounted, and it would need to work directly with the appropriate /dev/ file for your USB device. I would look at the 'man' page, and try one of the fatsort information switches first.
     
  21. altimar

    altimar Notebook Enthusiast

    Reputations:
    93
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    15
    Usage

    Examples:
    fatsort -h
    fatsort /dev/sda
    fatsort -c -oa /dev/sda1

    Timber's right. If you don't know what device it is, insert it and let it mount automatically, then on a command line run 'mount'. In the output, look for the mount directory (/media/FEDORA/) and on the same line it should show the device (sda1, sdb1).

    BTW, thanks guys for bringing fatsort to my attention. I have the same problem with a Creative Zen Stone Plus.
     
    Last edited by a moderator: May 8, 2015