0

I know there are directories like /bin, /sbin, /usr/bin, /usr/local/bin and so on, and that files in those directories can be run directly from the terminal. How does the terminal know to look at those paths?

I've heard that the paths are stored in /etc/bash.bashrc or ~/.bashrc, but /sbin is not present in those files. Is there a specific file in which the paths are set, and can we add our own paths, other than using bashrc?

3
  • 1
    Look at the output of echo $PATH. Then look inside of /etc/environment file. Maybe you will make an idea. Apr 6, 2014 at 18:54
  • @RaduRădeanu PATH = (/etc/environment + bashrc)'s containments ? is it true? Apr 6, 2014 at 19:00
  • 2
    First time the value for PATH is assigned in /etc/environment file, then its value can be changed in any shell initialization files. Apr 6, 2014 at 19:17

3 Answers 3

2

/etc/environment contains all data about path of that programs you can add new path there.

Path included in /etc/environment, /etc/bash.bashrc , ~/.bashrc and ~/.profile is automatically initialized after loging into shell.

2
  • terminal look at /etc/environment or bashrc? Apr 6, 2014 at 19:08
  • +1 ... but.. still again, terminal look at /etc/environment or bashrc? which one ? both of them ? If yes how? By profile? Apr 6, 2014 at 19:16
0

Yes PATH variable. You can create your own bin directory as follows: mkdir $HOME/bin Add $HOME/bin to the PATH variable using bash shell export command: export PATH=$PATH:$HOME/bin echo $PATH Move hello.sh in $HOME/bin using the mv command, run: mv hello.sh $HOME/bin Execute the script at any path: hello.sh

3
  • when you type "export PATH=$PATH:$HOME/bin" this path save in where? Apr 6, 2014 at 19:28
  • Saved in PATH, the variable. PATH is a variable name, bash.bashrc is a file(a script) that configured some behavior of bash, these behavior might need to use the variable PATH. PATH is the basics.
    – Shawn Ma
    Apr 6, 2014 at 19:39
  • On Ubuntu, there is no need to add ~/bin to $PATH, it already is included by default. Apr 5, 2015 at 15:26
0

The paths for executable scripts and files are in the PATH environment variable:

env | grep PATH
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .