Is there a way to use a different field separator for the long output of ls?

I have problems in parsing the output of ls -l because some fields, in my case the group, contain spaces.

I went through man ls but I didn't see any viable option for me.

Also, IFS="AA" ls -l, doesn't work. (I thought ls would work with IFS.)

  • 5
    The real answer is: Don't parse the output of ls. This calls for problems. What are you really trying to do? Please read: mywiki.wooledge.org/XyProblem
    – slhck
    Feb 24, 2014 at 15:32
  • 6
    That's excactly why you shouldn't parse the output of ls. Ususally you can reach you goal easily when using stat, find etc. instead.
    – mpy
    Feb 24, 2014 at 15:33
  • @slhck: so far I deemed the long format of ls a source of many info in one shot. Nice reading the X-Y problem. I agree but this means questions should open and not to-the-point as the forum requires. But if users agree I'm fine with it. Specifically for my case I excluded the group (ls -G) Feb 25, 2014 at 11:44
  • It's ok to ask questions that are answerable as long as you're also fine to accept "don't do it like this" as an answer—which is the case here. The mention of the XY problem is just a hint to try and step back a little. It helps in some cases :)
    – slhck
    Feb 25, 2014 at 12:22

2 Answers 2


There is no way to tell ls to do this.

The output from ls is not meant to be parsed in this way.

You should use stat instead. This is how you would get the group's name for filename:

stat -c %G filename
  • 1
    The presence of spaces in the group field jumbled the ls output, I was not interested in the group field (excluded via the -G option) but I thought I would solve the issue via field separators. Thanks for confirming it Feb 25, 2014 at 11:50

You can use ls -n to get the user and group IDs as integers instead of names. If you're actually interested in those values, you'd have to convert them to names yourself after parsing.

  • @user2984629: The point was that numbers don't have spaces in them. But, indeed, I should have been more explicit, rather than thinking that it was obvious.
    – rici
    Feb 26, 2014 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .