Results 1 to 5 of 5
Hi,
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 ...
- 08-07-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 2
Methods to making a file executable
Hi,
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!
Bill
- 08-07-2011 #2
Hello and Welcome. To change file permissions to executable
Code:cd /path/to/file/
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.Code:chmod +x filename
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.
- 08-07-2011 #3
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.DISTRO=Arch
Registered Linux User #388732
- 08-07-2011 #4Just Joined!
- Join Date
- Aug 2011
- Posts
- 2
Alright. Thanks guys! B-)
- 08-12-2011 #5Linux Guru
- Join Date
- May 2011
- Posts
- 1,838
Afterthought: you can also define an alias for your program in your login profile. E.g., in your ~/.bashrc, you might have:
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.:Code:alias myprog='/opt/app/bin/myprog'
Code:alias adminprog='sudo /opt/app/sbin/myprog -v'


1Likes
Reply With Quote