PDF download Download Article
Learn to use the "echo $Path command to check directory paths
PDF download Download Article

If you've typed a command and see the error "command not found," it might mean the directory in which your executable is saved hasn't been added to your path. This wikiHow teaches you how to find the full path to a file, how to display your path environment variables, and how to add new directories to your path when necessary.

Using "echo $PATH" to Check Your Directory Paths

If you're getting a "command not found" error in Unix, you can use the echo $PATH command to see which directories your shell is checking for executable files. If you're trying to run a command from a directory not in that list, you'll get a "not found" error.

  1. If you need to find the absolute path to a file on your system, you can do so using the find command. Let's say you needed to find the full path to a program called fun:
    • Type find / -name "fun" –type f print and press Enter.
      • This shows the full path to the file called fun no matter which directory you're in.
      • If fun in a directory called /games/awesome, you'd see /games/awesome/fun in the results of the command.
  2. When you type a command, the shell looks for it in the directories specified by your path. You can use echo $PATH to find which directories your shell is set to check for executable files. To do so:
    • Type echo $PATH at the command prompt and press Enter.
      • The results should look something like this: usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      • This output is a list of directories where executable files are stored. If you try to run a file or command that isn't in one of the directories in your path, you'll receive an error that says the command is not found.
    Advertisement
  3. Let's say you want to run that file called fun. You learned from running the find command that it's in a directory called /games/awesome. However, /games/awesome is not in your path, and you don't want to type the full path just to run the game. To add it to your path:[1]
    • Type export PATH=$PATH:/games/awesome and press Enter.
      • Now you can run fun just by typing its name at the command line (instead of /games/awesome/fun) and pressing Enter.
      • This change only affects the current shell. If you open a new terminal window or sign in elsewhere, you'll have to re-add the path. To make the change permanent, add the command to your shell's config file (e.g., .bashrc, .cshrc).
  4. Advertisement

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Video

Tips

  • By default, the shell does not search your current directory in Unix-type OSes (BSD, Linux, etc.) unless it's already in your path. This can be fixed by adding a period (dot), which is the Unix short-cut for the current directory. This can be changed by going to your home directory. This should contain '.profile'. Use an editor, such as vi, to open, change, and save.
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

Warnings

Advertisement

You Might Also Like

Run a Program from the Command Line on LinuxRun a Program from the Command Line on Linux
Sudo Command Not Found2 Ways to Fix the "Sudo Command Not Found" Error on Linux
Change the PATH Environment Variable on Windows Change the PATH Environment Variable on Windows
Use Windows Command Prompt to Run a Python File Use Command Prompt to Run a Python File on Windows
Zsh: Command Not Found: BrewEasy Fixes for the “zsh: Command Not Found: Brew” Error
Open Applications Using Terminal on MacOpen Applications Using Terminal on Mac
Set Java Home Set JAVA_HOME for JDK & JRE: A Step-by-Step Guide
Run a Batch File from the Command Line on Windows Run a Windows Batch File from the Command Line (CMD)
Write a Shell Script Using Bash Shell in UbuntuWrite a Shell Script Using Bash Shell in Ubuntu
Run Files in LinuxRun Files in Linux
Use MS DOS Use MS DOS
Run a Program on Command Prompt Run a Program at the Windows Command Prompt: 2 Ways
Zsh: Permission Denied Fix the Zsh: Permission Denied Error on Mac
Linux How to SymlinkCreate Symbolic Links in Linux: Everything You Need to Know
Advertisement

About This Article

Nicole Levine, MFA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 348,875 times.
How helpful is this?
Co-authors: 9
Updated: November 29, 2024
Views: 348,875
Categories: Operating Systems
Article SummaryX

1. Use echo $PATH to view your path variables.
2. Use find / -name "filename" –type f print to find the full path to a file.
3. Use export PATH=$PATH:/new/directory to add a new directory to the path.

Did this summary help you?

Thanks to all authors for creating a page that has been read 348,875 times.

Is this article up to date?

Advertisement