Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-22-2007, 09:42 AM   #1
LQ Newbie
Registered: Jun 2007
Posts: 10

Rep: Reputation: 0
ls -> Column Order


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!

Old 06-22-2007, 10:45 AM   #2
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:

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

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
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:
/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
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.


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 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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:17 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration