Questions tagged [path]

The general form of a file or directory name that specifies a unique location in a file system. In many Linux and Unix-like OS the PATH (all upper case) variable specifies the directories where executable programs are searched for.

A path represents a unique file system location using the directory tree hierarchy expressed in a string of characters in which path components, separated by a delimiting character, represent each directory. The delimiting character is most commonly a slash /, a backslash \, or a colon :.

A PATH (all upper case, ) in the Linux, UNIX-like operating systems and Windows contains list of directories, where the shell searches through, when a command is executed. The executables are stored in different directories in the OS. On UNIX-like OS the directories are separated by colon, on Windows by semi-colon.

Examples

Simple way to show the $PATH variable is:

echo "$PATH"
printf "%s\n" "$PATH"

A typical PATH looks like:

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

More generally, a path is a sequence of directions that, when followed in order, reach a certain object or location.

In addition to file system paths, there are paths through a tree:

root->left->right->right->left

or, again more generally, a set of attributes on an object.


There might be some other contexts where the term "path" is used to described something non-URI and non-directory related which are not covered by the general description.

One case would be in a context such as in the SCADA software, Ignition, where the term "path" is generally used to refer to tag-path - as Tag is the basic unit in the software, forming a hierarchical system like directory. Typical tag-path in Ignition look like this:

BaseFolder/MyTag

Or, more complexly when tag is not in the BaseFolder but referred from another "Parent" Tag:

BaseFolder/MyAdvanceUDTTag/MyBaseUDTTag/MyTag
19410 questions
5551
votes
27 answers

How do I create a directory, and any missing parent directories?

How do I create a directory at a given path, and also create any missing parent directories along that path? For example, the Bash command mkdir -p /path/to/nested/directory does this.
Parand
  • 102,950
  • 48
  • 151
  • 186
1622
votes
31 answers

How do I get the filename without the extension from a path in Python?

How do I get the filename without the extension from a path in Python? "/path/to/some/file.txt" → "file"
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
1488
votes
42 answers

Path.Combine for URLs?

Path.Combine is handy, but is there a similar function in the .NET framework for URLs? I'm looking for syntax like this: Url.Combine("http://MyUrl.com/", "/Images/Image.jpg") which would return: "http://MyUrl.com/Images/Image.jpg"
Brian MacKay
  • 31,133
  • 17
  • 86
  • 125
1283
votes
23 answers

Extract file name from path, no matter what the os/path format

Which Python library can I use to extract filenames from paths, no matter what the operating system or path format could be? For example, I'd like all of these paths to return me c: a/b/c/ a/b/c \a\b\c \a\b\c\ a\b\c a/b/../../a/b/c/ a/b/../../a/b/c
BuZz
  • 16,318
  • 31
  • 86
  • 141
1071
votes
24 answers

How to permanently set $PATH on Linux/Unix

On Linux, how can I add a directory to the $PATH so it remains persistent across different sessions? Background I'm trying to add a directory to my path so it will always be in my Linux path. I've tried: export PATH=$PATH:/path/to/dir This works,…
Ali
  • 261,656
  • 265
  • 575
  • 769
1069
votes
32 answers

Importing modules from parent folder

I am running Python 2.5. This is my folder tree: ptdraft/ nib.py simulations/ life/ life.py (I also have __init__.py in each folder, omitted here for readability) How do I import the nib module from inside the life module? I am hoping…
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
1019
votes
36 answers

How to get full path of a file?

Is there an easy way I can print the full path of file.txt ? file.txt = /nfs/an/disks/jj/home/dir/file.txt The dir> file.txt should print /nfs/an/disks/jj/home/dir/file.txt
Jean
  • 21,665
  • 24
  • 69
  • 119
1018
votes
12 answers

mkdir -p functionality in Python

Is there a way to get functionality similar to mkdir -p on the shell from within Python. I am looking for a solution other than a system call. I am sure the code is less than 20 lines, and I am wondering if someone has already written it?
Setjmp
  • 27,279
  • 27
  • 74
  • 92
1017
votes
11 answers

How to get an absolute file path in Python

Given a path such as "mydir/myfile.txt", how do I find the file's absolute path in Python? E.g. on Windows, I might end up with: "C:/example/cwd/mydir/myfile.txt"
izb
  • 50,101
  • 39
  • 117
  • 168
1004
votes
28 answers

How to use to find files recursively?

I would like to list all files recursively in a directory. I currently have a directory structure like this: src/main.c src/dir/file1.c src/another-dir/file2.c src/another-dir/nested/files/file3.c I've tried to do the following: from glob import…
Ben Gartner
  • 14,413
  • 10
  • 36
  • 34
931
votes
33 answers

Setting environment variables on OS X

What is the proper way to modify environment variables like PATH in OS X? I've looked on Google a little bit and found three different files to edit: /etc/paths ~/.profile ~/.tcshrc I don't even have some of these files, and I'm pretty sure that…
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
921
votes
23 answers

Reliable way for a Bash script to get the full path to itself

I have a Bash script that needs to know its full path. I'm trying to find a broadly-compatible way of doing that without ending up with relative or funky-looking paths. I only need to support Bash, not sh, csh, etc. What I've found so far: The…
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
773
votes
13 answers

How can I set the current working directory to the directory of the script in Bash?

I'm writing a Bash script. I need the current working directory to always be the directory that the script is located in. The default behavior is that the current working directory in the script is that of the shell from which I run it, but I do not…
jameshfisher
  • 34,029
  • 31
  • 121
  • 167
706
votes
22 answers

Adding a directory to the PATH environment variable in Windows

I am trying to add C:\xampp\php to my system PATH environment variable in Windows. I have already added it using the Environment Variables dialog box. But when I type into my console: C:\>path it doesn't show the new C:\xampp\php…
Netorica
  • 18,523
  • 17
  • 73
  • 108
694
votes
23 answers

How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)?

Question: is there a simple sh/bash/zsh/fish/... command to print the absolute path of whichever file I feed it? Usage case: I'm in directory /a/b and I'd like to print the full path to file c on the command-line so that I can easily paste it into…
dhardy
  • 11,175
  • 7
  • 38
  • 46
1
2 3
99 100