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

  • 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 6 '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 6 '18 at 17:16
  • 4
    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 6 '18 at 17:30
  • For a precise example of @gardenhead's suggestion, since you mention permissions, check out stat --format=%A . – Izkata Feb 6 '18 at 19:06

First ensure that dotglob is off:

shopt -u dotglob

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

ls -ld . .. *

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 6 '18 at 16:38

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.