Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I watched a video lecture today that introduced C and things like how to make a C program that will run in Linux. I followed the steps given and now I'm stuck with a bit of a problem.

I created my C file (HelloWorld.c) and used the command gcc -o HelloWorld HelloWorld.c to compile the file, both of these steps were successful. Afterwards I checked to make sure that HelloWorld had been created by using the command ls, and it had been. However, when I use the command HelloWorld, which is supposed to run the program, I get an error that says HelloWorld: command not found.

In the video lecture the professor did mention that this worked for 32-bit systems and I'm using a 64-bit system. Perhaps this could be the problem?

EDIT: Also in the video lecture the professor mentioned that when I use the command ls I should see HelloWorld*. I see only HelloWorld (without the star).

share|improve this question
up vote 8 down vote accepted

You don't have the value of the PATH environment variable set to include whatever directory the HelloWorld executable file lives in.

Supposing you have used cd to get to the directory, you can run HelloWorld with this command: ./HelloWorld

Linux shells have a concept called PATH, which is a list of directories in which to look when the user issues a command without a fully-qualified path name (/usr/bin/ls is fully qualified: it starts at '/' and ends at 'ls', but ls is not fully-qualified). If you don't have an entry of '.' in PATH, you have to explicitly use "./" on the beginning of a command to get the file of that name in the current directory to execute.

share|improve this answer
Thanks! This is exactly what I needed to know. – brewer2 May 3 '11 at 21:07
It's worth pointing out that '.' is not in PATH for security reasons, and therefore it is a bad idea to add it. In case anyone thinks this was some unaccountable oversight on the part of their OS provider. – Faheem Mitha May 4 '11 at 8:27
How would you run the program with command-line arguments, then? – Anderson Green Oct 16 '12 at 0:49

Use ls -F to see a star at the end of filename. You can set the environment variable LS_OPTIONS to automatically include this and any other number of options for you. The commands for ls are listed in the ls man page, to see them run: man ls

@brewer2: setting environment variables on login is shell specific and a good question in itself.

share|improve this answer
How would I set LS_OPTIONS to automatically include -F? – brewer2 May 3 '11 at 21:15
While I think the accepted answer is the right one, this is also good to know. – Mr. Shickadance May 3 '11 at 21:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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