Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Methods to making a file executable


    I was wondering: if I want to make a file/shell script runnable by typing in its name (or a shortcut for the name), is it then really necessary to add the directory of the file to the $PATH of my shell?
    I mean, the larger the PATH is, the longer it takes for the shell to find the appropriate program, no?

    Is there no other way (like creating a shortcut, similar like I would have done in Windows)
    I suppose I could create a symbolic link to the file and put in in the /usr/local/sbin directory, but what is the Jedi way?

    Thanks in advance!


  2. #2
    Administrator MikeTbob's Avatar
    Join Date
    Apr 2006
    Hello and Welcome. To change file permissions to executable
    cd /path/to/file/
    chmod +x filename
    If the file is in a directory other than what is in your path, it won't be found. For example, if the file is in /usr/sbin/ but you do not have /usr/sbin/ defined in your system path, you'll get a "not found" error probably.
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

    I'd rather be lost at the lake than found at home.

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    So, as you know, executable files must be located in a directory in your $PATH in order to be executed without being given the full path. As you rightly observe, there are three approaches to this:

    1) Add the binary's directory to $PATH. This used to be somewhat common when /opt was used. Now, however, it's not very popular. It is more preferred to have a few standard directories. Having said that, this does sometimes happen.

    2) Copy the binary into a directory in $PATH. This is the most common approach. It is taken by the "install" program that is generally invoked as a part of the "make install" command that you run when you compile a new program.

    3) Create a symlink for your binary in a directory in $PATH. This is done, but probably not as much as 2). It is generally used for smaller, personal programs. The problem with doing this for standard programs is that depending on where the symlink points to, it may be difficult for other users to access the binary, and it ties a file in a systemwide directory to something in someone's home directory, which could make it easy to break.

    I have a ~/bin directory that contains symlinks for little utilities that I wrote, and that are only accessible to me. Everything else pretty much gets copied into /usr/local/bin.

  4. $spacer_open
  5. #4
    Alright. Thanks guys! B-)

  6. #5
    Afterthought: you can also define an alias for your program in your login profile. E.g., in your ~/.bashrc, you might have:
    alias myprog='/opt/app/bin/myprog'
    although this technique is usually more popular when you want to call the prog a certain way or pass default command line arguments to it, e.g.:
    alias adminprog='sudo /opt/app/sbin/myprog -v'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts