LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-11-2006, 04:17 PM   #1
swatward
Member
 
Registered: Jan 2005
Distribution: slackware
Posts: 83

Rep: Reputation: 15
Arranging Files In Alphabetical order


This seems like it'd be really simple, but how do i arrange files by alphabetical order from command line.

If i have
aaa.mp3
fff.mp3
bbb.mp3
that should be
aaa
bbb
fff.

How do i Do this?
I'm just blanking out here.
 
Old 12-11-2006, 04:20 PM   #2
zetabill
Member
 
Registered: Oct 2005
Location: Rhode Island, USA
Distribution: Slackware, Xubuntu
Posts: 348

Rep: Reputation: 32
Normally ls gives it's output in alphabetical order by default. Are you using something else?
 
Old 12-11-2006, 04:24 PM   #3
swatward
Member
 
Registered: Jan 2005
Distribution: slackware
Posts: 83

Original Poster
Rep: Reputation: 15
er sorry, yeah bad questions. I have an upload script that also lists the files a a certain order, but it's doing it in some random order.

Heres the code for the sorting part

PHP Code:
$handle=opendir($upload_dir);
$filelist "";
while (
$file readdir($handle)) {
   if(!
is_dir($file) && !is_link($file)) {
      
$filelist .= "
<table border=1><tr><td bgcolor='white' width='100%'><a href='
$upload_dir$file'>".$file."</a></td>";

      
$filelist .="";
   } 
 
Old 12-11-2006, 05:29 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Put the results of readdir in an array, and then call sort on it. You can then iterate over the array and test for directories and links (and discard them).

You can see an example here. It must be true - google told me.
 
Old 12-11-2006, 08:14 PM   #5
swatward
Member
 
Registered: Jan 2005
Distribution: slackware
Posts: 83

Original Poster
Rep: Reputation: 15
aight cool, thanks.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to 'sort' by file extension then alphabetical order adamrosspayne Linux - Newbie 4 07-04-2006 10:53 PM
Alphabetical sort wierdness SuperNull Linux - General 2 11-18-2005 12:21 AM
what files must i edit in order to: fazaman Debian 1 02-23-2005 08:33 AM
Alphabetical Listing of Text trihai44100 Linux - Software 1 03-13-2004 11:34 AM
Dual bootup. Arranging order amoskoh Linux - General 1 01-25-2003 12:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:01 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