LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-22-2007, 10:42 AM   #1
daletaylor
LQ Newbie
 
Registered: Jun 2007
Posts: 10

Rep: Reputation: 0
ls -> Column Order


Hello,

Is there a way to sort the columns with the 'ls' command?

What I'm trying to do is have the file/directory names in the first column, and all the other information to the right of it.

Thanks a lot!

-Dale
 
Old 06-22-2007, 11:45 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
The difficulty with putting the filenames first is that you can't predict how wide that first column should be.

If you get past that, though, you can transmogrify the output of the ls output. Do this at the shell prompt:

Code:
man cut
man paste
Hope this helps.
 
Old 06-22-2007, 11:50 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
It may take a very complicated awk script to do it half way decently and then it still wouldn't look good.
You would have to keep track of the filesize and filename widths on each page of output and use that to adjust the field widths. Otherwise the columns wouldn't line up.

Try this badly written awk script for your self. You'll see what I mean:
Code:
/total/ { print $0 }
! /total/ {
printf "%-40s", $NF
print $1,$2,$3,$4,$5,$6,$7
}
ls -l | awk -f ls.awk

Last edited by jschiwal; 06-22-2007 at 12:06 PM.
 
Old 06-22-2007, 11:59 AM   #4
daletaylor
LQ Newbie
 
Registered: Jun 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Thank for the replies!

I guess I'll just get used to having them on the right though.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Erratic column? Hitboxx LQ Suggestions & Feedback 3 03-03-2007 11:53 AM
ls column description anjanesh Linux - Newbie 5 01-04-2006 05:45 AM
add id in the first column alaios Linux - General 1 11-19-2004 07:49 AM
Column limit agallant Programming 1 08-05-2004 11:58 AM
add new column Eddie9 Linux - General 2 04-09-2002 01:05 PM


All times are GMT -5. The time now is 01:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration