3

Is there a way to list all files and directories including . and .. but without listing hidden files in this folder?

yossico
  • 141
  • 2
    This seems like an XY problem. You know those hardlinks will always be there, so what's the purpose of listing them? My only guess is that you want to parse the output of ls, which is a shell faux pas. – gardenhead Feb 06 '18 at 16:30
  • @gardenhead I have existing code that parse ls output and I need to know the current folder permissions in order to enable/disable items in the UI. is there a better way than parsing ls do list files with their permissions? – yossico Feb 06 '18 at 17:16
  • 4
    https://unix.stackexchange.com/questions/128985/why-not-parse-ls. If you need to get the file permissions, I would recommend running stat on each file in a for loop. – gardenhead Feb 06 '18 at 17:30
  • For a precise example of @gardenhead's suggestion, since you mention permissions, check out stat --format=%A . – Izkata Feb 06 '18 at 19:06

2 Answers2

11

First ensure that dotglob is off:

shopt -u dotglob

Then just ask ls for those two directories and everything else:

ls -ld . .. *
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
3

I think it could be easy to define the following as an alias for instance:

ls -ld \. \.\. *
  • 4
    You don't need the backslashes, the dot isn't special to the shell. (It is in regexes, but shell filename patterns aren't regexes.) – ilkkachu Feb 06 '18 at 16:38