What Is Path on a MAC (Unix) System

What is PATH on a Mac (UNIX) system?

PATH is a special environment variable in UNIX (and UNIX-like, e.g. GNU/Linux) systems, which is frequently used and manipulated by the shell (though other things can use it, as well).

There's a somewhat terse explanation on wikipedia, but basically it's used to define where to search for executable files (whether binaries, shell scripts, whatever).

You can find out what your current PATH is set to with a simple shell command:

: $; echo $PATH

(Note: the : $; is meant to represent your shell prompt; it may be something very different for you; just know that whatever your prompt is, that's what I'm representing with that string.)

Depending on your system and prior configuration, the value will vary, but a very simple example of the output might be something like:

/usr/bin:/bin:/usr/local/bin

This is a colon(:)-separated list of directories in which to search for executable files (things like ls, et cetera.) In short, when you try to execute a command from your shell (or from within some other program in certain ways), it will search through each of the directories in this list, in order, looking for an executable file of the name you're provided, and run the first one it finds. So that's the concept, per your question.

From there, what this documentation is telling you to do is to add the directory where you've unpacked the software, and in particular its bin subdirectory, into your $PATH variable. How to do this depends a bit on which shell you're using, but for most (Bourne-compatible) shells, you should be able to do something like this, if you're in the directory where that bin directory is:

: $; PATH="$PATH:$PWD/bin"; export PATH

In just about all but an actual Bourne shell, this can be shortened to:

: $; export PATH="$PATH:$PWD/bin"

(I won't bother explaining for CSH-compatible shells (because: I agree with other advice that you don't use them), but something similar can be done in them, as well, if that happens to be your environment of choice for some reason.)

Presumably, though, you'll want to save this to a shell-specific configuration file (could be ~/.profile, ~/.bashrc, ~/.zshrc... depending on your shell), and without reference to $PWD, but rather to whatever it expanded to. One way you might accomplish this would be to do something like this:

: $; echo "export PATH=\"\$PATH:$PWD/bin\""

and then copy/paste the resulting line into the appropriate configuration file.

Of course you could also generate the appropriate command in other ways, especially if your $PWD isn't currently where that bin directory is.

See also:

  • An article about $PATH (and more)
  • a related question on superuser.com

Displaying finder directory path in unix format on mac os x yosemite

Dragging the file or folder into terminal gives you the path in unix form

Where is the default terminal $PATH located on Mac?

If you do sudo man path_helper, it talks a bit about how it puts the path together. You might look in /etc/paths and /etc/paths.d. I did, and found what I was looking for.

Setting PATH environment variable in OSX permanently

You have to add it to /etc/paths.

Reference (which works for me) : Here

Mac / Unix: overwritten path variable

These changes are local to this one command prompt. Just open another terminal window.

If you need the normal value of $PATH to use in this one specific terminal window, open another one and copy its $PATH value.

If you want changes to $PATH to persist, you need to write a .bashrc file or a .profile file in your home folder with the $PATH-altering commands you wish to use. To revert, take them out.

What is /home directory in Mac OS used for?

Simply put, the /home directory is used for nothing on macOS.

While it's typically the location for user homes in Linux and Unix, macOS uses /Users instead. If you want to write portable programs, simply use $HOME or ~ to refer to the home directory.

Mac OS Equivalent file path for Windows file path

In Finder, do a right-click on the file of which you need the path. Then press the Option key (alt) to open the context menu. Select Copy "name_of_file" as path. Then you have the path, for example

/Library/Preferences/com.apple.AppleFileServer.plist

To get the file URI, add file://, like so

file:///Library/Preferences/com.apple.AppleFileServer.plist

Mac unix script: given a list of file paths, find the one with latest modified date?

For OS X's stat:

tr \\n \\0<files.txt|xargs -0 stat -f'%m %N'|sort -rn|head -n1

Use -c'%Y %n' with GNU stat.

Different ways to find files sorted by modification date:

find . -type f -exec stat -f'%m %N' {} +|sort -rn|cut -d' ' -f2-
for OS X's stat; use -c'%Y %n' with GNU stat
gfind -type f -printf '%T@ %p\n'|sort -rn|cut -d' ' -f2-
%T@ is absolute modification time and %p is pathname
zsh -o dotglob -c 'printf %s\\n **/*(.om)'
. is a qualifier for regular files
om orders files by modification time


Related Topics



Leave a reply



Submit