LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ls -> Column Order (https://www.linuxquestions.org/questions/linux-newbie-8/ls-column-order-563711/)

daletaylor 06-22-2007 09:42 AM

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

wjevans_7d1@yahoo.co 06-22-2007 10:45 AM

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.

jschiwal 06-22-2007 10:50 AM

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

daletaylor 06-22-2007 10:59 AM

Thank for the replies!

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


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