0

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.

Tiana
  • 3

1 Answers1

0

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" ;;
    esac
done
Chris Down
  • 125,559
  • 25
  • 270
  • 266