LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 09: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, 10:45 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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, 10:50 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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 11:06 AM.
 
Old 06-22-2007, 10: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



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 10:53 AM
ls column description anjanesh Linux - Newbie 5 01-04-2006 04:45 AM
add id in the first column alaios Linux - General 1 11-19-2004 06:49 AM
Column limit agallant Programming 1 08-05-2004 10:58 AM
add new column Eddie9 Linux - General 2 04-09-2002 12:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:23 PM.

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