PDA

View Full Version : ls -l command change order of columns listed


e3den
02-18-2009, 02:43 PM
Hi!
Im novice over here, i am trying to configure the osx terminal like as ms-dos, and well when i type a comand like ls -la all files and directories are on the last column instead of the first column.
I like order as
File name, size, data, user, links and permisions

its possible?
Thanks!!

hayne
02-18-2009, 04:33 PM
I don't think it's possible to configure the order of info in the output from 'ls -l'
But you could achieve the sort of thing you are looking for by use of appropriate options to the command 'stat'
(read 'man stat')

e3den
02-19-2009, 06:41 AM
can you teach me an example?? pleasee.
Im noob on unix
Thanks!

hayne
02-19-2009, 11:53 AM
See this Unix FAQ (http://hayne.net/MacDev/Notes/unixFAQ.html) for an intro to using Unix commands on OS X.

But as a newbie, I'd strongly recommend that you not try to make the environment the same as what you are used to (MS-DOS). Instead you should use it as is for some months to get used to it. Customization is suitable after you know the system.

Hal Itosis
02-19-2009, 10:50 PM
can you teach me an example?? pleasee.
Im noob on unix
hayne is right, the columns in ls are not reorder-able to the extent you requested,
and it's best to learn how to deal with ls on its own terms. He's also right that stat
is probably your best bet. [read up on the -f option... it works like printf and date]

Fortunately for you, i have a shell function that i can just copy & paste, without much
work involved. When i want to call it, i just type sx (so i don't confuse it with ls ;) ):

sx ()
{
local x='%6p %Sp %3l %8.15Su %8.15Sg %#7Of %8z %N%T%SY'
local y=$@; [ $# -eq 0 ] && y=.*\ *
printf '\e[4m octal permission links owner '
printf ' group flags size name \e[0m\n'
/usr/bin/stat -f "$x" $y
}



File name, size, data, user, links and permisions
data? -- not sure what that means. Having the file name first means you'll need to
restrict its width, or the columns won't line up. Using my script as a template, this
value for x might get you started:

local x='%-16N %8z %8.15Su %3l %Sp'

-HI-

Hal Itosis
11-01-2009, 01:01 AM
Slight bug in the sx function above (w.r.t. spaces in filenames, when a "folder/*" type of argument is given). This approach seems to work much better...


function sx ()
{
local x='%6p %Sp %3l %8.15Su %8.15Sg %#7Of %8z %N%T%SY'
local y=; [ $# -eq 0 ] && y=.*\ *
printf '\e[4m octal permission links owner '
printf ' group flags size name \e[0m\n'
/usr/bin/stat -f "$x" ${y:-"$@"}
}

[intended for a bash shell btw]

Mikey-San
11-01-2009, 07:11 AM
Hi!
Im novice over here, i am trying to configure the osx terminal like as ms-dos


Why? If it's a matter of familiarity, you're better off simply getting used to the platform instead of trying to make the platform work like something else, like Hayne said.