Posted: 1/21/2012 4:49:50 PM EDT
| I a noob when it comes to Unix/Linux. Lets say I am in my home directory and I want to run a program that is not located in that same directory but below it. How do I run the program without using cd to change to the directory? |
|
Quoted:
You'll have to use the full path name if it is not in your path as defined in your local or global profile. You could add the path to the location of the binary in your path statement if this is going to be a high use binary for you. Haha thats what I was doing. I went back to double check my path and realized that I was miss spelling the program name. Thanks for the help. |
|
Quoted:
Quoted:
../<program> Wouldnt ../program go up one directory and look for the program, instead of down? Depends on how you define up and down
Given the directory /home/user/some-directory/ ../<program> will run /home/program ./some-directory/program will run /home/user/some-folder/program proved you are already in the /home/user directory Alternatively in most bash systems you can use '~' to address the current users home directory ~/some-directory/program will run /home/<current user>/some-directory/program |
|
Yep, that would be the full path for a binary one directory from your current working directory. As an example, the /usr/bin directory should already be in your PATH statement so you can run 'ls' w/o having to type /usr/bin/ls. You can add any directory to your PATH statement so if you have a binary that you normally call with /home/username/bin/program_name you can add /home/username/bin to your PATH variable and execute the binary by name instead of path. The search path problems come into play when you have a binary with a duplicate name. The directories in your PATH statement will be searched in order so if you have /usr/bin before /home/username/bin and your binary is called 'ls' (just as an example) then the first instance in /usr/bin will be used and /home/username/bin/ls will not be run.
Quoted:
Quoted:
../<program> Wouldnt ../program go up one directory and look for the program, instead of down? |
|
Most shells have a PATH variable that contains a list of directories in which to look for an 'open' string-of-text that could be an executable file.
You can add the needed directory to the PATH variable, or go to a directory already in the PATH variable and make a symbolic link to the executable. |
|
"Up" in Unix is / . is the current working directory .. is one directory up (back "up" toward / ) If you're in /home/billybob and you have a subdirectory foo within your home directory and in it you have a program named bar, you can run it with the fulll pathname specified: /home/billybob/foo/bar or with a relative pathname specified ./foo/bar |