Ok so, I know ls -a lists files including the hidden ones, and * command includes the elements I want to include. ls -I ".." -I "..." does not work as I have to use ls -a.


1 Answer 1


GNU ls has --almost-all, or -A, which lists all directory entries except for . and ..:

   -A, --almost-all
          do not list implied . and ..
$ touch foo bar baz
$ ls -A
bar  baz  foo

Otherwise, portably, you can use globs with a case statement:

for dirent in * .*; do
    case $dirent in
        .|..) continue ;;
        *)    [ -e "$dirent" ] && printf '%s\n' "$dirent" ;;

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.