ComputerBasForum

Hier tips en tricks

Je bent niet ingelogd.

#1 2022-04-12 21:34:03

Bas
Administrator
Geregistreerd: 2019-11-10
Posts: 70

PATH

Manual for adding directories to your PATH in Linux systems:

In Linux, executable programs live inside several different directories on your system. Any file with executable permissions stored in these directories can be run from any location. The most common directories that hold executable programs are /bin, /sbin, /usr/sbin, /usr/local/bin and /usr/local/sbin. When you type a command, the shell searches through all directories specified in the user PATH variable for an executable file of that name. The PATH environmental variable is a colon-delimited list of directories that tells the shell which directories to search for executable files. To check what directories are in your PATH, you can use either the printenv or echo command:

echo $PATH

The output will look something like this:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

If you have executable files sharing the same name located in different directories, the shell will run the file that comes first in PATH !!

Adding a directory to your PATH:

For example:

Add home/bin to your PATH type:

export PATH="$HOME/bin:$PATH"

This will set the shell child process environments, however, this change is only temporary and valid only in the current shell session.

To make the change permanent, you need to define the PATH variable in the shell configuration files.
Environment variables are read from the following files:

Global shell:

/etc/environment
/etc/profile

(Use to add to all system users PATH.)

Per-user shell:

Set the variable in the ~/.bashrc file

Open the file:

nano ~/.bashrc

Add the following line:

export PATH="$HOME/bin:$PATH"

Save the file and load the new PATH into the current shell session using the source command:

source ~/.bashrc

To confirm that the directory was successfully added to PATH:

Type in new console:

echo $PATH

Conclusion:

Adding new directories to your user or global PATH variable allows you to execute commands, programs and scripts stored on nonstandard locations without needing to type the full path to the executable.

Yes you can!

Laatst bewerkt door Bas (2022-04-22 14:45:41)

Offline

Forum footer

Powered by FluxBB