I have just found a couple of examples using [ -a some_dir ] or [ -a some_file ] but can't find what the -a operator is for. It seems it should be described in the man page for test/[ but there it is just as a comparison operator [ $expr1 -a $expr2 ]. It seems it simply returns true if a file or dir exists, no matter the type or so.


In bash and some other shells, -a is a synonym for -e (true if file exists).

$ help test
      -a FILE        True if file exists.
      -e FILE        True if file exists.

This is non-standard and not supported in all shells, so you better don't rely on it.

Notice that the manpage of test(1) documents the external command (/usr/bin/test, /usr/bin/[, etc), not the shell built-in.

  • and help is a shell builtin command that provides help on shell builtin commands. – X Tian Aug 6 at 9:17
  • 2
    @XTian help is a bash built-in command which provides incomplete help on built-in commands ;-) – mosvy Aug 6 at 9:23
  • I was not aware of the difference between command and builtin. It is too often pointed out test and [ are the same command residing in /usr/bin. So, what is used whilst I am really testing with [? :)) – Honza Hejzl Aug 6 at 10:02
  • 1
    You're always using the shell built-in no matter if you call it as [ or test (unless you disabled it with eg enable -n [). – mosvy Aug 6 at 10:16
  • btw, the external test/[ from GNU coreutils (the /usr/bin/test in "desktop" linux) used to support the unary -a. It no longer does – mosvy Aug 6 at 10:20

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.