0

Is there a way to get GNU coreutils ls (or any other open-source ls) to omit the trailing symbol (* for executable, / for directory, etc.) only when output is piped?

the GNU ls has a --color[=WHEN] option accepting auto to automatically show colors when output is not piped, and omit the control sequences for colors when output is piped. I am looking for identical behavior regarding trailing symbols indicating filetype.

1 Answer 1

1

Presumably you have an alias for ls that's unconditionally adding the -F (or --classify) option. I would work around that by creating a wrapper function that tests whether the stdout is a terminal or not; only add the -F option if the output is a terminal.

function ls {
  if [ -t 1 ]
  then
    command ls -F "$@"
  else
    command ls "$@"
  fi
}

Adjust the other default options as you like.

You must log in to answer this question.

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