Things are not "executable" that are written by the user by default, you have to make it executable... chmod +x /path-to/filename.ext then you can execute it with the absolute or relevant path name ./filename.ext ~/Folder/filename.ext /path/to/Folder/filename.ext Answer from acejavelin69 on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › how-to-run-file-in-linux
How to Run a File in Linux - GeeksforGeeks
July 23, 2025 - Right-click on the file, choose "Open With", and select the appropriate application to open it. Here is how you can do it - ... You may see your file running now. To run a file in Linux using the terminal, follow these steps: 1. Navigate to the ...
🌐
Stack Overflow
stackoverflow.com › questions › 35259825 › linux-how-to-run-execute-a-file-in-the-command-line-without-the
linux - how to run/execute a file in the command line without the ./ - Stack Overflow
the idea is to do this way in any directory, not only one in specific! 2016-02-07T22:40:41.723Z+00:00 ... Edit your "$PATH" variable to include the directory in which this file is located. For example, this is a part of my "$PATH": /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/rany/bin ... After putting an executable script in one of these directories you'll be able to execute it by simply typing its name at the command line.
🌐
Wikihow
wikihow.com › computers and electronics › operating systems › linux › how to run files in linux: 9 steps (with pictures) - wikihow
How to Run Files in Linux: 9 Steps (with Pictures) - wikiHow
June 18, 2025 - If asked to do so, enter the password you use to log into your Linux computer and press Enter. ... Type the command to run the file. The command you use to open the file is going to be a different depending on the file type. Enter one of the following commands and press Enter to run the file.
🌐
Living the Linux Lifestyle
livingthelinuxlifestyle.wordpress.com › 2020 › 02 › 09 › how-to-execute-files-in-linux
How to Execute Files in Linux – Living the Linux Lifestyle
February 9, 2020 - You can mark some files as executable within the GUI. Start your favorite file manager, then navigate to the desired program. Right-click the program, then select the “Permissions” tab. Under Execute, change the permissions to the desired value, such as Only Owner, Only Owner and Group, or Anyone.
🌐
Quora
quora.com › How-do-I-run-a-file-in-terminal-using-Linux
How to run a file in terminal using Linux - Quora
Answer (1 of 5): You can only run executable files. You can confer executable properties to any file using the chmod command. You need to do this if the file is a script that you wrote. If the file was created by a compiler & linker, it almost certainly has executable permissions. If you don't kn...
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
how do you execute a file from terminal? / Newbie Corner / Arch Linux Forums
Not being able to run executable files in the same directory as you are in is a security measure. You can always do ./$executable as said before, or, if it's a script, call the interpreter to execute it: ... Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 ...
Top answer
1 of 6
129

The literal answer is as others have given: because the current directory isn't in your $PATH.

But why? In short, it's for security. If you're looking in someone else's home directory (or /tmp), and type just gcc or ls, you want to know you're running the real one, not a malicious version your prankster friend has written which erases all your files. Another example would be test or [, which might override those commands in shell scripts, if your shell doesn't have those as built-ins.

Having . as the last entry in your path is a bit safer, but there are other attacks which make use of that. An easy one is to exploit common typos, like sl or ls-l. Or, find a common command that happens to be not installed on this system — vim, for example, since sysadmins are of above-average likelyhood to type that.

Does this sound too theoretical? It largely is, but it definitely can happen in reality, especially on multi-user systems. In fact, here is an example from this site where an administrator switched to a users' home directory and found ps to be masked by an executable of that name.

2 of 6
101

In Linux, UNIX and related operating systems, . denotes the current directory. Since you want to run a file in your current directory and that directory is not in your $PATH, you need the ./ bit to tell the shell where the executable is. So, ./foo means run the executable called foo that is in this directory.

You can use type or which to get the full path of any commands found in your $PATH.

Find elsewhere
🌐
Wikihow
wikihow.com › computers and electronics › operating systems › linux › how to execute .run files (& more) in linux: 2 easy ways
How to Execute .RUN Files (& More) in Linux: 2 Easy Ways
July 9, 2025 - In the default file manager in Ubuntu and many other versions of Linux, you can do this by right-clicking (or control-clicking) the file you want to run and selecting Properties. It should be similar in other file managers.
🌐
Linux Mint Forums
forums.linuxmint.com › board index › interests › programming & development
running executables in terminal - Linux Mint Forums
So Linux Mint 21 won't be affected by this issue and executables will run from the file manager. That said, if you want to run executable binaries from a terminal when you double-click them in Nemo you have to use something like above (or a Nemo action, or …).
🌐
Gcore
gcore.com › home › developers › how to make a file executable in linux
How to Make a File Executable in Linux | Step-by-step Guide
April 8, 2025 - Running an Executable. Once a file is executable, you can run it from the terminal. If the file is in your current directory, you’d typically prefix it with ./, as in ./my_script.sh. Let’s walk through the steps to make a file executable in Linux.
🌐
MakeUseOf
makeuseof.com › home › linux › how to read and execute from a file with the linux source command
How to Read and Execute From a File With the Linux source Command
September 23, 2022 - To test it out, write the commands in the code box above in a new file and use the source command instead of making it executable. # Create a new file and edit it vi test file . test_file echo $TEST # This will return "bed" As you can see, using the source command, you were able to update the environment variables of the parent process. This is the primary use case of the source command, i.e., to modify the parent environment. ... That's all the steps you need to update the Bash shell environment with the source command. The difference between Linux bash and source commands is that when you execute a script with the bash command, it tells the Linux kernel to create a new Bash process to read and execute the script, copy the output to the original shell process, and display it.
🌐
Baeldung
baeldung.com › home › files › why do we use ./ (dot slash) to execute a file in linux
Why Do We Use ./ (Dot Slash) To Execute a File in Linux | Baeldung on Linux
March 18, 2024 - In this tutorial, we’ll learn when and how to use “./” for running a script in Linux. We’ll also explain how the path search works in Linux in general and Bash in particular. Let’s assume we want to run the script.sh file that is an executable and lives in the current directory.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › linux exec command with examples
Linux exec Command With Examples
December 11, 2025 - The Linux exec command executes a Shell command without creating a new process. Instead, it replaces the currently open Shell operation. Depending on the command usage, exec has different behaviors and use cases. This article will demonstrate how to use the exec command in Linux.
Top answer
1 of 4
41

The definitive answer to "how programs get run" on Linux is the pair of articles on LWN.net titled, surprisingly enough, How programs get run and How programs get run: ELF binaries. The first article addresses scripts briefly. (Strictly speaking the definitive answer is in the source code, but these articles are easier to read and provide links to the source code.)

A little experimentation show that you pretty much got it right, and that the execution of a file containing a simple list of commands, without a shebang, needs to be handled by the shell. The execve(2) manpage contains source code for a test program, execve; we'll use that to see what happens without a shell. First, write a testscript, testscr1, containing

#!/bin/sh

pstree

and another one, testscr2, containing only

pstree

Make them both executable, and verify that they both run from a shell:

chmod u+x testscr[12]
./testscr1 | less
./testscr2 | less

Now try again, using execve (assuming you built it in the current directory):

./execve ./testscr1
./execve ./testscr2

testscr1 still runs, but testscr2 produces

execve: Exec format error

This shows that the shell handles testscr2 differently. It doesn't process the script itself though, it still uses /bin/sh to do that; this can be verified by piping testscr2 to less:

./testscr2 | less -ppstree

On my system, I get

    |-gnome-terminal--+-4*[zsh]
    |                 |-zsh-+-less
    |                 |     `-sh---pstree

As you can see, there's the shell I was using, zsh, which started less, and a second shell, plain sh (dash on my system), to run the script, which ran pstree. In zsh this is handled by zexecve in Src/exec.c: the shell uses execve(2) to try to run the command, and if that fails, it reads the file to see if it has a shebang, processing it accordingly (which the kernel will also have done), and if that fails it tries to run the file with sh, as long as it didn't read any zero byte from the file:

        for (t0 = 0; t0 != ct; t0++)
            if (!execvebuf[t0])
                break;
        if (t0 == ct) {
            argv[-1] = "sh";
            winch_unblock();
            execve("/bin/sh", argv - 1, newenvp);
        }

bash has the same behaviour, implemented in execute_cmd.c with a helpful comment (as pointed out by taliezin):

Execute a simple command that is hopefully defined in a disk file somewhere.

  1. fork ()
  2. connect pipes
  3. look up the command
  4. do redirections
  5. execve ()
  6. If the execve failed, see if the file has executable mode set. If so, and it isn't a directory, then execute its contents as a shell script.

POSIX defines a set of functions, known as the exec(3) functions, which wrap execve(2) and provide this functionality too; see muru's answer for details. On Linux at least these functions are implemented by the C library, not by the kernel.

2 of 4
13

In part, this depends on the particular exec family function that's used. execve, as Stephen Kitt has shown in detail, only runs files in the correct binary format or scripts that begin with a proper shebang.

However, execlp and execvp go one step further: if the shebang wasn't correct, the file is executed with /bin/sh on Linux. From man 3 exec:

Special semantics for execlp() and execvp()
   The execlp(), execvp(), and execvpe() functions duplicate the actions
   of the shell in searching for an executable file if the specified
   filename does not contain a slash (/) character.
   …

   If the header of a file isn't recognized (the attempted execve(2)
   failed with the error ENOEXEC), these functions will execute the
   shell (/bin/sh) with the path of the file as its first argument.  (If
   this attempt fails, no further searching is done.)

This is somewhat supported by POSIX (emphasis mine):

One potential source of confusion noted by the standard developers is over how the contents of a process image file affect the behavior of the exec family of functions. The following is a description of the actions taken:

  1. If the process image file is a valid executable (in a format that is executable and valid and having appropriate privileges) for this system, then the system executes the file.

  2. If the process image file has appropriate privileges and is in a format that is executable but not valid for this system (such as a recognized binary for another architecture), then this is an error and errno is set to [EINVAL] (see later RATIONALE on [EINVAL]).

  3. If the process image file has appropriate privileges but is not otherwise recognized:

    1. If this is a call to execlp() or execvp(), then they invoke a command interpreter assuming that the process image file is a shell script.

    2. If this is not a call to execlp() or execvp(), then an error occurs and errno is set to [ENOEXEC].

This doesn't specify how the command interpreter is obtained, so, but doesn't specify that an error has to be given. I guess, therefore, that the Linux devs allowed such files to be run with /bin/sh (or this was already a common practice and they just followed suit).

FWIW, the FreeBSD manpage for exec(3) also mentions similar behaviour:

 Some of these functions have special semantics.

 The functions execlp(), execvp(), and execvP() will duplicate the actions
 of the shell in searching for an executable file if the specified file
 name does not contain a slash ``/'' character. 
 …
 If the header of a file is not recognized (the attempted execve()
 returned ENOEXEC), these functions will execute the shell with the path
 of the file as its first argument.  (If this attempt fails, no further
 searching is done.)

AFAICT, however, no common shell uses execlp or execvp directly, presumably for finer control over the environment. They all implement the same logic using execve.

🌐
Medium
medium.com › @peey › how-to-make-a-file-executable-in-linux-99f2070306b5
How to make a file executable in linux? | by Peeyush Kushwaha | Medium
August 30, 2016 - To execute a file all we need to do is enter the path of the file on the command prompt. We’ll also need execute permissions on the file, like to read a file we’d need read permissions.