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
  • See [how to glob every hidden file except current and parent directory](https://unix.stackexchange.com/questions/1168/how-to-glob-every-hidden-file-except-current-and-parent-directory) – steeldriver Feb 02 '22 at 01:56

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
  • 122,090
  • 24
  • 265
  • 262