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.

1

1 Answer 1

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

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.