[opensuse] copying files to USB flashdisk in alphabetical order
Hello: My old mp3 player plays the files in the order as they were copied to the disk. Until now I used to copy the files in the correct order by this command: find . -print0 | sort -z | xargs -0 cp -a --parents --target-directory=/media/disk This used to copy directories and their files recursively in alphabetocal order. But in openSUSE 12.2 it does not work. The files are copied to my sdcard in random order. Why is this and how could I fix it? Thanks, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 09/07/2013 10:13 AM, Istvan Gabor wrote:
Hello:
My old mp3 player plays the files in the order as they were copied to the disk.
Until now I used to copy the files in the correct order by this command:
find . -print0 | sort -z | xargs -0 cp -a --parents --target-directory=/media/disk
This used to copy directories and their files recursively in alphabetocal order.
But in openSUSE 12.2 it does not work. The files are copied to my sdcard in random order.
Why is this and how could I fix it?
Thanks,
Istvan
Maybe you should erase/reformat the card first? -- Explain again the part about rm -rf / -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 09/07/2013 07:13 PM, Istvan Gabor wrote:
Hello:
My old mp3 player plays the files in the order as they were copied to the disk.
Until now I used to copy the files in the correct order by this command:
find . -print0 | sort -z | xargs -0 cp -a --parents --target-directory=/media/disk
This used to copy directories and their files recursively in alphabetocal order.
But in openSUSE 12.2 it does not work. The files are copied to my sdcard in random order.
Why is this and how could I fix it?
Unfortunately, you didn't write how the files are copied. So my guesses out of the blue: Did you verify that the output of sort(1) is what you expected? Please try something like $ find . -print0 | sort -z | xargs -0 printf "%s\n" But as a general note: sort(1) is inherently dependent on the current locale(1). Probably/maybe you want to set LC_ALL=C like this: $ find . -print0 | LC_ALL=C sort -z | xargs -0 ... Finally, find(1) will probably include and print the directories first ... which will make the sorting order for cp(1) useless because it will first copy the whole directory and then recognize that it has to copy the files in it (which has already been done). Did you mean this? $ find . -type f -print0 | LC_ALL=C sort -z | xargs -0 ... Have a nice day, Berny -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
2013. szeptember 10. 3:23 napon Bernhard Voelker
On 09/07/2013 07:13 PM, Istvan Gabor wrote:
Hello:
My old mp3 player plays the files in the order as they were copied to the disk.
Until now I used to copy the files in the correct order by this command:
find . -print0 | sort -z | xargs -0 cp -a --parents --target-directory=/media/disk
This used to copy directories and their files recursively in alphabetocal order.
But in openSUSE 12.2 it does not work. The files are copied to my sdcard in random order.
Why is this and how could I fix it?
Unfortunately, you didn't write how the files are copied. So my guesses out of the blue:
I don't understand what you mean "how files are copied". I wrote I use cp -a --parents --target-directory=/media/disk
Did you verify that the output of sort(1) is what you expected? Please try something like
Yes I tried. The command find . -print0 | sort -z | xargs -0 writes the names all the files and directories in alphabetical order to the screen.
But as a general note: sort(1) is inherently dependent on the current locale(1). Probably/maybe you want to set LC_ALL=C like this:
$ find . -print0 | LC_ALL=C sort -z | xargs -0 ...
I have en_US.UTF-8 locale and all the files and directory name in this folder have only iso latin1 characters. No accented characters. The output is something like this: . ./01 ./01/01.mp3 ./01/02.mp3 ./01/03.mp3 ./01/04.mp3 ./01/05.mp3 ./01/06.mp3 ./01/07.mp3 ./01/08.mp3 ./01/09.mp3 ./01/10.mp3 ./01/11.mp3 ./01/12.mp3 ./02 ./02/01.mp3 ./02/02.mp3 ./02/03.mp3 ./02/04.mp3 ./02/05.mp3 ./02/06.mp3 ./02/07.mp3 ./02/08.mp3 ./02/09.mp3 ./02/10.mp3
Finally, find(1) will probably include and print the directories first ... which will make the sorting order for cp(1) useless because it will first copy the whole directory and then recognize that it has to copy the files in it (which has already been done). Did you mean this?
I think you are not right. What is important, this command always worked in my previous systems. In openSUSE 12.2 it does not work. (I haven tested it in 12.1). Since copying the files is pretty slow I can check how the files are appearing on the sdcard. They are appearing randomly, not in alphabetical order. Directory 03 is created before 01, and file 08 is created before 02, for example. Might this be related to: 1) sync / async option of mounted media 2) temporary media filesystem 3) or something else? Thank you for your answer. Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 09/11/2013 06:22 PM, Istvan Gabor wrote:
2013. szeptember 10. 3:23 napon Bernhard Voelker
írta: Unfortunately, you didn't write how the files are copied. So my guesses out of the blue:
I don't understand what you mean "how files are copied".
I meant how the result actually looks like. You provided an example below ...
I wrote I use cp -a --parents --target-directory=/media/disk
Maybe you add the -v option to see in which order cp(1) copies the files.
The output is something like this:
. ./01 ./01/01.mp3 ./01/02.mp3 ./01/03.mp3 ./01/04.mp3 ./01/05.mp3 ./01/06.mp3 ./01/07.mp3 ./01/08.mp3 ./01/09.mp3 ./01/10.mp3 ./01/11.mp3 ./01/12.mp3 ./02 ./02/01.mp3 ./02/02.mp3 ./02/03.mp3 ./02/04.mp3 ./02/05.mp3 ./02/06.mp3 ./02/07.mp3 ./02/08.mp3 ./02/09.mp3 ./02/10.mp3
Ah! Here is the problem .... and I described it in the next sentence:
Finally, find(1) will probably include and print the directories first ... which will make the sorting order for cp(1) useless because it will first copy the whole directory and then recognize that it has to copy the files in it (which has already been done). Did you mean this?
I think you are not right.
The above means that cp(1) first copies "." - which means the whole directory hierarchy -, and then continues with "./01" ... which is also a directory which has already been copied. Or in other words: all arguments after "." are redundant and therefore do in no way influence the order of copying. Therefore, cp(1) processes the "." directory as it always does: it just reads the directory entries, and this is usually done on the order of their creation. Notice the order of creation of the directories and files: $ mkdir 01 03 02 $ touch 01/01.mp3 02/02.mp3 03/03.mp3 To see what would be executed, I put a simple echo before cp(1): $ find . -print0 | sort -z | xargs -0 echo cp -a --parents --target-directory=/tmp/target -v cp -a --parents --target-directory=/tmp/target -v . ./01 ./01/01.mp3 ./02 ./02/02.mp3 ./03 ./03/03.mp3 And when executing that command, you see that first "." is processed - in the order of the above creation: `./01' -> `/tmp/target/./01' `./01/01.mp3' -> `/tmp/target/./01/01.mp3' `./03' -> `/tmp/target/./03' `./03/03.mp3' -> `/tmp/target/./03/03.mp3' `./02' -> `/tmp/target/./02' `./02/02.mp3' -> `/tmp/target/./02/02.mp3' .... and then the rest is copied (again!) which even given you some warnings for the directories: cp: will not create hard link `/tmp/target/./01' to directory `/tmp/target/./01' `./01/01.mp3' -> `/tmp/target/./01/01.mp3' cp: will not create hard link `/tmp/target/./02' to directory `/tmp/target/./02' `./02/02.mp3' -> `/tmp/target/./02/02.mp3' cp: will not create hard link `/tmp/target/./03' to directory `/tmp/target/./03' `./03/03.mp3' -> `/tmp/target/./03/03.mp3'
What is important, this command always worked in my previous systems. In openSUSE 12.2 it does not work. (I haven tested it in 12.1).
The only reason you were satisfied with the results at that time could be that the files have already been created in the order you wanted ... incidentally. Hope this helps. Have a nice day, Berny -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (3)
-
Bernhard Voelker
-
Istvan Gabor
-
John Andersen