Linux run program from any directory

How can I make a program executable from everywhere

What should I do if I want to be able to run a given program regardless of my current directory? Should I create a symbolic link to the program in the /bin folder?

/bin/ folder, add THAT to your path, and create symlinks in that folder to anything you wanted to be executable from anywhere.

5 Answers 5

If you just type export PATH=$PATH:

at the command line it will only last for the length of the session.

If you want to change it permanently add export PATH=$PATH:

/.bashrc file (just at the end is fine).

/.zshrc with the PATH variable

The short answer is that to run the program, no matter what your directory, you need to have the program’s directory in your search path. The problem can be solved by putting the program into a folder thats already in that path, or by adding a new folder to the path — either will work. The best answer depends on:

Is this program a downloaded program that you have compiled yourself from source?

Its quite likely will have an install mechanism already. In the folder that you compiled the program, as root, run ‘make install’

Is this program a downloaded program that you want to make available as part of the standard programs on the computer?

Makes sense to put this kind of application into a standard folder. its quite common to use directories such as /usr/local/bin for such programs. You will need root access to do this.

This is a program that you have written for yourself and/or you have no special privilages on the computer.

Creating a folder in your home directory called ‘bin’, and placing the program in there. You may need to edit your login script to add the full path to this folder (e.g. /usr/home/jeremy/bin)

Whilst you could just add its current directory to the search path, you will have to keep doing this with every new program — and is more work in the longer term.

Placing a link to the file in the /bin directory isn’t the best thing to do for multiple reasons.

  • If the actual executable file is in a location that some users can’t see or execute, they see it as a bad link or dysfunctional program.
  • The /bin directory is supposed to be reserved for programs which are required for running the system (things like chmod , mkdir , etc).
Читайте также:  Connect to the internet to activate windows 10 что это

You can actually place (install) the executable file in /usr/bin/ or even /usr/local/bin/ . Of course, you’ve manually installed the program at that point; your distribution isn’t going to keep track of it the way it does the rest of your programs — you’ll have to manually upgrade it when necessary and manually remove it if you want it gone. Also, you’ll have to know what packages it depends on (it sounds like you already use the program, so that’s taken care of, but in general. ).

Unless I’m setting up a program that I expect other users to use, that’s not what I usually do: I create a bin directory just for me in my home directory, and I edit my shell profile to add

/bin/ to my PATH environment variable. I find it easier to keep track of the programs I’ve installed that way, because it is separated from the rest of the system.

Источник

Run a program from any directory in Ubuntu 16.04

I have installed the astronomy software CASA in my computer, and I would like to be able to run it from any directory just by typing casa in the Ubuntu terminal. What should I change so that this is possible? I’ve tried the following:

. but it doesn’t work. I’m no expert in Ubuntu, how can I fix this? As the previous line suggests, so far I can only access the program CASA in the following location:

/bin and add it to the PATH (see How to add a directory to the PATH?); or if other people use the PC, move the program into /usr/bin.

1 Answer 1

You have two issues to address from my finds:

    You are obviously not following the steps correctly as I did and have successfully ran it using casa command, though the link says casapy .

Solution please follow the steps verbatim.

  • sudo mkdir /usr/local/bin/CASA
  • sudo mv casapy-30.0.9860-001-64b.tar.gz /usr/local/bin/CASA
  • cd /usr/local/bin/CASA
  • sudo tar zxvf casapy-30.0.9860-001-64b.tar.gz
  • Add this to your

/.bashrc file and then source it with source

/.bashrc :

  • export PATH=$PATH:/usr/local/bin/CASA/casapy-30.0.9860-001-64b/bin
  • Test it with: casa

    Library issues. The latest version works on Ubuntu Xenial, and the version your installing might not work on your version of Ubuntu as I discovered when I tried to install your version 4.* on it. So get back to your instructor for further help.

    Important Note:

    You might want to install it on a Virtual Device as I noticed your version insisted on creating a user with id 1001 irrespective of who owns that id. In my case the user koko was made the group owner of the /usr/local/bin/CASA/* directory. Permission given to folder:

    Change the casapy-30.0.9860-001-64b to the one you download or the name seen there after extraction

    Источник

    How can i run a linux executable from any directory in terminal?

    I know that the linux commands like ls, cd and others are executables and can be accessed from any directory. My question is how can i run an executable created by me from any directory in terminal ?

    3 Answers 3

    Read about the PATH variable. It could be set by your shell. Check with echo $PATH its current value. It is also used by several exec(3) functions. BTW, having a long $PATH is bad taste and messy (and could be inefficient).

    If your login shell is /bin/bash you could edit your

    /.bashrc (used for interactive shells) to add something like

    but on several recent Linux distributions, the $HOME/bin/ directory is already part of your PATH , and you might add scripts, executables, or symlinks to them in it.

    So (when $HOME/bin is mentioned in $PATH ) I don’t recommend extending your PATH , but rather adding appropriate executables, executable scripts or symlinks into that $HOME/bin/ directory.

    Of course, if you have some executable in $HOME/someproject/someprog you can still explicitly run it with a shell command starting with $HOME/someproject/someprog .

    Your build procedure might also have some installation step. For example, if you use GNU make as your build automation, you might have an install phony target in your Makefile which copies the executable after its compilation into some appropriate place. See also hier(7) & install(1), and autoconf.

    Источник

    How to run programs from a different directory in unix

    I know this is a very simple question, and that many similar (but more complicated!) questions have been asked- So i wanted to ask this in a very plane manner. Sorry if this voids the rules of conduct on this website! I’m very new to using unix.

    I have a program that converts a «.evt» file to an .rq1, which is used for data analysis. The command to do so is simple, for example: Convert data.evt (this outputs data.rq1).

    This program, let’s say, is located in directory /A and I have a data file that I want to convert in directory /B. How would I go about executing this program without moving the convert program to directory B?

    5 Answers 5

    It is very simple:

    It means go to the directory A and run the program with parameter that you will give.

    In UNIX File System, all your inbuilt commands are binaries (programs) written to perform certain tasks. ls command does the listing of directories, mv command moves or renames files etc.

    All these binaries are stored in your /usr/bin directory. And the path to that directory is stored in your PATH environment variable.

    If you have many scripts that do certain tasks, I would recommend them to move in one folder. say for example, /yourname/scripts and then set this path in your PATH variable.

    PATH variable can be set in your .bashrc or .bash_profile file which gets loaded up whenever you fire a terminal session. You can view your PATH variable settings by doing an echo on it.

    ]$ echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/mysql/bin:/Developer/usr/bin:/usr/local/ActivePerl-5.12/bin:/Library/Ruby/Site/1.8/rubygems:/Library/Ruby/Gems/1.8/gems/wkpdf-0.5.3-universal-darwin/bin:/Library/Ruby/Gems/1.8/gems/wkpdf-0.5.3-universal-darwin/lib

    In your .profile file, simply add :/yourname/scripts folder and do . .profile on your shell prompt. This will force your current session to load your profile file without having to quit and log in again.

    Once the .profile file has been loaded, you can run your script from anywhere by simply typing scriptname options or other arguments as needed.

    Источник

    How do I run a program with a different working directory from current, from Linux shell?

    Using a Linux shell, how do I start a program with a different working directory from the current working directory?

    For example, I have a binary file helloworld that creates the file hello-world.txt in the current directory.

    This file is inside of directory /a .

    Currently, I am in the directory /b . I want to start my program running ../a/helloworld and get the hello-world.txt somewhere in a third directory /c .

    11 Answers 11

    Call the program like this:

    The parentheses cause a sub-shell to be spawned. This sub-shell then changes its working directory to /c , then executes helloworld from /a . After the program exits, the sub-shell terminates, returning you to your prompt of the parent shell, in the directory you started from.

    Error handling: To avoid running the program without having changed the directory, e.g. when having misspelled /c , make the execution of helloworld conditional:

    Reducing memory usage: To avoid having the subshell waste memory while hello world executes, call helloworld via exec:

    [Thanks to Josh and Juliano for giving tips on improving this answer!]

    Similar to David Schmitt’s answer, plus Josh’s suggestion, but doesn’t leave a shell process running:

    This way is more similar to how you usually run commands on the shell. To see the practical difference, you have to run ps ef from another shell with each solution.

    An option which doesn’t require a subshell and is built in to bash

    Источник

    Читайте также:  Как windows server 2012 gpt
  • Оцените статью