I wrote a simple C program on a different Linux computer. I would compile it using

gcc guess.c

That would output an a.out file. I would then just type the command a.out, and my C program would run.

I attempted to run the same C program on my Pi. It compiles well and outputs an a.out file. Though when I attempt to run the command "a.out", I get an error:

-bash: a.out: command not found.

Does anyone know how to get a.out support working on the Pi?

  • 2
    I would also add the flag "-Wall" to your gcc command, to display all warning messages. Sep 20, 2013 at 10:32
  • This could be considered PI related as the OP has observed different behavior on their PI than from previous non-PI experience. Granted, the answer to the question is a pure UNIX/Linux answer, but many PI questions/issues are UNIX/Linux related. Sep 20, 2013 at 14:47
  • 2
    "Basically, if you're question is about the Raspberry Pi or about something that happens on the Raspberry Pi you are in the right place." Direct quote from the help center as to what is on topic. Sep 20, 2013 at 15:22
  • 2
    @MorganK It's arguable. But we feel that currently it's directed more toward usage of bash usage, and thus is a generic Linux question, as your issue will occur on any Linux system, rather than just on the Raspberry Pi. Please come to Raspberry Pi Chat if you wish to discus further!
    – Jivings
    Sep 20, 2013 at 16:15
  • @MorganK I'm not mad, but what is the reasoning for you accepting the answer you did over mine? It's perfectly fine that you did, I'm just wondering how to improve answers in the future so they are accepted.
    – syb0rg
    Sep 21, 2013 at 1:10

2 Answers 2


you should type:


if your file is in the current directory.

also, you might check if executable bit is set with

ls -al a.out

and if not, set it using

chmod +x a.out

however, most compilers will set executable bit for you automagically.

  • It is also worth to mention that you can not execute the binary if the binary is not compiled for the specific platform(arm).
    – ortang
    Sep 22, 2013 at 10:06
  • The file command will report the details of an executable file, including ARM vs x86. Jun 15, 2018 at 17:14

You need to put a ./ in front of a.out in order to execute that:

When you type the name of a program such as a.out the system looks for the file in your PATH. On my system, PATH is set to


Yours is probably similar. To check, enter echo $PATH in a terminal.

The system looks through these directories in the order given and if it can't find the program produces a command not found error.

Prepending the command with ./ effectively says "forget about the PATH, I want you to look only in the current directory".

Similarly you can tell the system to look in only another specific location by prepending the command with a relative or absolute path such as:

./Debug/hello : "look for hello in the Debug subdirectory of my current directory."

or /bin/ls : "look for ls in the directory /bin"

By default, the current directory is not in the path because it's considered a security risk. See Why is . not in the path by default? on Superuser for why.

It's possible to add the current directory to your PATH, but for the reasons given in the linked question, I would not recommend it.

I'm not sure why the answer said not to change your PATH, since the answer on SuperUser said that this was a "very lame and useless anti-virus measure, and nothing stops you from adding dot to the path yourself."

  • Having "." in your PATH means that as you change your current directory, any file in the current directory that has the same name as a command you are used to typing (or mis-typing) will be executed. It is generally safer to install executable files in known directories in PATH. Of course, you can always use a path to execute a local file, "./<file>". Apr 9, 2021 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.