How to decide on the sort with ls - Suse

This is a discussion on How to decide on the sort with ls - Suse ; When you do a `ls -U` you get the order of the files unsorted. From the
man pages:
-U do not sort; list entries in directory order
I have a car radio that shows files in this order. The files ...

You might consider piping through 'sort' - as I recall, it is much more
flexible.

Re: How to decide on the sort with ls

ray wrote:
> On Sun, 13 Jan 2008 13:55:40 +0100, houghi wrote:
>
>> When you do a `ls -U` you get the order of the files unsorted. From the
>> man pages:
>> -U do not sort; list entries in directory order
>>
>> I have a car radio that shows files in this order. The files are mp3
>> files I ripped from my CD's
>>
>> Here a sample of some files:
>> #v+
>> [/mnt/pink_floyd/the_wall]
>> houghi@penne : l -U
>> total 112576
>> drwxr-xr-x 2 houghi root 16384 2007-10-13 10:43 ./
>> drwxr-xr-x 4 houghi root 16384 2008-01-11 07:50 ../
>> -rwxr-xr-x 1 houghi root 4668317 2007-10-07 21:35 03_Another_Brick_In_The_Wall_(Part_1).mp3*
>> -rwxr-xr-x 1 houghi root 2174976 2007-10-07 21:34 18_Bring_The_Boys_Back_Home.mp3*
>> -rwxr-xr-x 1 houghi root 4353583 2007-10-07 21:35 15_Is_There_Anybody_Out_There.mp3*
>> -rwxr-xr-x 1 houghi root 6250688 2007-10-07 21:35 11_Don't_Leave_Me_Now.mp3*
>> -rwxr-xr-x 1 houghi root 8098271 2007-10-07 21:35 06_Mother.mp3*
>> -rwxr-xr-x 1 houghi root 2755272 2007-10-07 21:34 04_The_Happiest_Days_Of_Our_Lives.mp3*
>> -rwxr-xr-x 1 houghi root 1949275 2007-10-07 21:33 12_Another_Brick_In_The_Wall_(Part_3).mp3*
>> -rwxr-xr-x 1 houghi root 3440750 2007-10-07 21:34 25_The_Trial.mp3*
>> -rwxr-xr-x 1 houghi root 2218214 2007-10-07 21:35 17_Vera.mp3*
>> -rwxr-xr-x 1 houghi root 4697745 2007-10-07 21:35 16_Nobody_Home.mp3*
>> #v-
>>
>> So when I play the files on the car radio, I first hear number 03, then
>> 18, the 15 and so on. That is obviously not very nice.
>>
>> I can not change the order on the car radio to look at the name of the
>> file, so I must do the changes on the PC.
>>
>> So how can I change the order of the entries in the directory?
>>
>> houghi
>
> You might consider piping through 'sort' - as I recall, it is much more
> flexible.

Could you elborate on that? How do I get then to a correct `l U`?

houghi
--
Dr. Walter Gibbs: Won't that be grand? Computers and the programs
will start thinking and the people will stop.
-- Tron (1982)

Re: How to decide on the sort with ls

On Sun, 13 Jan 2008, houghi wrote:-
>When you do a `ls -U` you get the order of the files unsorted. From the
>man pages:
>-U do not sort; list entries in directory order
>
>I have a car radio that shows files in this order. The files are mp3
>files I ripped from my CD's

>I can not change the order on the car radio to look at the name of the
>file, so I must do the changes on the PC.
>
>So how can I change the order of the entries in the directory?

Are you intending to rebuild the CD? If so, this should help do the job:

#!/bin/bash

# assume the CD is already mounted on /mnt
#

# make a temporary directory to hold the sorted structure
#
mkdir /tmp/temp.dir

# now find all the files, sort the list and copy them into the temporary directory structure
#
find /mnt -type f | \
sort | \
while read DIR
do
cp "${DIR}" "/tmp/temp.dir${DIR:4}" # same as the above
done

Re: How to decide on the sort with ls

David Bolt wrote:
> Are you intending to rebuild the CD? If so, this should help do the job:

No, not realy I would have to dig them up. e.g. The Hobbit and Lord of
the Rings is a LOT of CD's. Those only is 50+ CD's or so. The same for
HHGTTG. I bought them, ripped them and then put them in a box and put
them away.

Shirley there must be another way to manipulate files and the order they
are in?

I tried to copy and also move the files one by one, but that did not
work. :-(

houghi
--
You are about to enter another dimension, a dimension not only of
sight and sound but of mind. A journey into a wondrous land of
imagination. Next stop, Usenet!

Re: How to decide on the sort with ls

On 2008-01-13 13:55, houghi wrote:
> When you do a `ls -U` you get the order of the files unsorted. From the
> man pages:
> -U do not sort; list entries in directory order
>
> I have a car radio that shows files in this order. The files are mp3
> files I ripped from my CD's
>
> Here a sample of some files:
> #v+
> [/mnt/pink_floyd/the_wall]
> houghi@penne : l -U
> total 112576
> drwxr-xr-x 2 houghi root 16384 2007-10-13 10:43 ./
> drwxr-xr-x 4 houghi root 16384 2008-01-11 07:50 ../
> -rwxr-xr-x 1 houghi root 4668317 2007-10-07 21:35 03_Another_Brick_In_The_Wall_(Part_1).mp3*
> -rwxr-xr-x 1 houghi root 2174976 2007-10-07 21:34 18_Bring_The_Boys_Back_Home.mp3*
> -rwxr-xr-x 1 houghi root 4353583 2007-10-07 21:35 15_Is_There_Anybody_Out_There.mp3*
> -rwxr-xr-x 1 houghi root 6250688 2007-10-07 21:35 11_Don't_Leave_Me_Now.mp3*
> -rwxr-xr-x 1 houghi root 8098271 2007-10-07 21:35 06_Mother.mp3*
> -rwxr-xr-x 1 houghi root 2755272 2007-10-07 21:34 04_The_Happiest_Days_Of_Our_Lives.mp3*
> -rwxr-xr-x 1 houghi root 1949275 2007-10-07 21:33 12_Another_Brick_In_The_Wall_(Part_3).mp3*
> -rwxr-xr-x 1 houghi root 3440750 2007-10-07 21:34 25_The_Trial.mp3*
> -rwxr-xr-x 1 houghi root 2218214 2007-10-07 21:35 17_Vera.mp3*
> -rwxr-xr-x 1 houghi root 4697745 2007-10-07 21:35 16_Nobody_Home.mp3*
> #v-
>
> So when I play the files on the car radio, I first hear number 03, then
> 18, the 15 and so on. That is obviously not very nice.
>
> I can not change the order on the car radio to look at the name of the
> file, so I must do the changes on the PC.
>
> So how can I change the order of the entries in the directory?
>
> houghi

ls *.mp3 > playlist.m3u
Then play the m3u file.

/bb

Re: How to decide on the sort with ls

On Mon, 14 Jan 2008, houghi wrote:-
>David Bolt wrote:
>> Are you intending to rebuild the CD? If so, this should help do the job:
>
>No, not realy I would have to dig them up.

Not unless you were planning on re-ripping the files. The script only
needs the discs with the MP3s on them. All it does is to copy the
contents from the mounted CD onto the hard drive, creates a sorted
directory list and builds a matching directory structure. Then it
creates a sorted file list and copies the files into the directories,
and finally builds a new ISO image for burning.
>Shirley there must be another way to manipulate files and the order they
>are in?

Not without creating a new CD, there isn't.
>I tried to copy and also move the files one by one, but that did not
>work. :-(

Try running the script, mounting the resultant image and looking at the
directory structure. A couple of quick tests here shows it does the job.

Re: How to decide on the sort with ls

birre wrote:
>> So how can I change the order of the entries in the directory?
>>
>
> ls *.mp3 > playlist.m3u
> Then play the m3u file.

Not an option. The radio does not recognize m3u files.

houghi
--
You are about to enter another dimension, a dimension not only of
sight and sound but of mind. A journey into a wondrous land of
imagination. Next stop, Usenet!

Re: How to decide on the sort with ls

David Bolt wrote:
> Not unless you were planning on re-ripping the files. The script only
> needs the discs with the MP3s on them.

Discs? What discs? I put them on a SD card and/or on a USB device. I
overwrite them when I want to listen to something else. I could try and
copy a directory one by one to the device, but I am sure there is a way
to do it on the HD itself.
>>Shirley there must be another way to manipulate files and the order they
>>are in?
>
> Not without creating a new CD, there isn't.

I find that highly unlikely. How is the order determined? There must be
some logic behind it. Also I am not trying to make a CD anyway. I just
try to change the order.

houghi
--
You are about to enter another dimension, a dimension not only of
sight and sound but of mind. A journey into a wondrous land of
imagination. Next stop, Usenet!

Re: How to decide on the sort with ls

On Mon, 14 Jan 2008, houghi wrote:-
>David Bolt wrote:
>> Not unless you were planning on re-ripping the files. The script only
>> needs the discs with the MP3s on them.
>
>Discs? What discs?

My assumption was that you were referring to CDs, not something else.
>I put them on a SD card and/or on a USB device. I
>overwrite them when I want to listen to something else. I could try and
>copy a directory one by one to the device, but I am sure there is a way
>to do it on the HD itself.

Probably.
>>>Shirley there must be another way to manipulate files and the order they
>>>are in?
>>
>> Not without creating a new CD, there isn't.
>
>I find that highly unlikely. How is the order determined? There must be
>some logic behind it. Also I am not trying to make a CD anyway. I just
>try to change the order.

# now find all the files, sort the list and copy them into the temporary directory structure
#
find "${TMP}" -type f | \
sort | \
while read DIR
do
cp "${DIR}" "${SD}/${DIR:${#TMP}}" # same as the above
done

Re: How to decide on the sort with ls

On Mon, 14 Jan 2008 11:31:59 +0100, houghi wrote:
> birre wrote:
>>> So how can I change the order of the entries in the directory?
>>>
>>
>> ls *.mp3 > playlist.m3u
>> Then play the m3u file.
>
> Not an option. The radio does not recognize m3u files.
>
> houghi

cd into the top directory containing your mp3 files.
Issue a command like the following:

find . -name '*.mp3' | sort | cpio -o | (cd /tmp; cpio -ivd)

Change /tmp to the directory that your sd card is mounted on -
/media/whatever. Also, you can add extra params to the find to control
what files will be transfered. Use the command up to the sort to show what
files will be transfered. The back to back cpio commands will copy the
files specified on standard input in the order specified.

regards,
Frank Ranner

Re: How to decide on the sort with ls

David Bolt wrote:
>>Discs? What discs?
>
> My assumption was that you were referring to CDs, not something else.

They are SOOOO last century. ;-)
>>I find that highly unlikely. How is the order determined? There must be
>>some logic behind it. Also I am not trying to make a CD anyway. I just
>>try to change the order.
>
> Okay, how about this then:

I think I am being not very clear. The end result is to be able to copy
to the SD card (which is in itself also a USB reader). However as much
as writing files one by one, I would like to sort correctly on the HD
already in such a way that whenever I copy to wherever, the order is
correct.

I will try the workaround when I am at home. It is a lousy workaround,
if you ask me. :-(
> #!/bin/bash
for I in `ls -1 *.mp3`;do cp $I /mnt/$I;done

I would think that that would work. I have tried :
mkdir tmp && for I in `ls -1 *.mp3`;do cp $I tmp/$I;done