3

I wanted to ask about the ls command in lubuntu 15.10. Now there is a new line for every entry. I know from other distributions that there is also an output style where ls outputs the content of folders without new lines in a compact way when typed without any options. Is that possible in lubuntu, too?

Edit:

The ls version is 8.23 and type ls outputs

ls is aliased to `ls --color=auto'

The -C flag does not create a different output than without any options.

I have read the manual man ls after the comment, but could not find anything relevant to my question there.

  • ls is part of coreutils and these should be the same all across. What kind of version you have? type in ls --version , let us know. Also , type ls output would be nice to know. ls also has -C flag, but that should be default in terminal - you wouldn't need that unless you are redirecting output to a file. – Sergiy Kolodyazhnyy Feb 13 '16 at 14:26
  • Reading man ls is a good first step. – waltinator Feb 13 '16 at 14:29
  • @waltinator man page for ls isn't very descriptive, info ls is a bit more in detail, which is the source of my knowledge about -C and -1 flags. OP's output suggests that he has ls -1 behavior , while ls -C should be the default. – Sergiy Kolodyazhnyy Feb 13 '16 at 14:39
  • 5
    Are there any files with unusually long names in the directory you are trying to list? That can prevent it from columnising the output. – steeldriver Feb 13 '16 at 14:40
  • 1
    @steeldriver good catch ! post an answer – Sergiy Kolodyazhnyy Feb 13 '16 at 14:45
2

Very long file names will force the output of ls to be one per line. You could rename the file to have a shorter file name.

Or you could try the below command which forcefully truncates file names (from this answer on Unix & Linux):

ls | cut -c1-20 | column -c"${COLUMNS:-80}"

If you wanted you could make a special alias to execute this with lc, for example, by adding the following to your ~/.bash_alisaes file:

alias lc='ls | cut -c1-20 | column -c"${COLUMNS:-80}"'

However that alias won't allow you to pass flags like -l or -a, so instead you could make a script ~/bin/lc and make it executable with chmod +x ~/bin/lc:

#!/usr/bin/env bash

ls $@ | cut -c1-20 | column -c"${COLUMNS:-80}"

Kudos @steeldriver for discovering the issue in the comments above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.