skistaddy
skistaddy

Reputation: 2224

Make executable symbolic link in Python?

I have a file called client.py. I created a symbolic link called incro using

ln -s client.py incro

How do I make this script executable and move it to my bin (I'm on Linux using Ubuntu, with a bash terminal), under the name of incro? So that I will be able to run

incro

I have the proper sha-bang. What else do I need to do?

Upvotes: 2

Views: 8946

Answers (4)

Khan
Khan

Reputation: 41

in your ~/.bashprofile ,add the line as "alias incro=/path/to/clientfile.py"

Upvotes: 0

Marcin
Marcin

Reputation: 454

By default symbolic links follow file permissions so you don't make symbolic link executable, but simply make your client.py file executable.

Command:

ln -s client.py incro

Creates relative symbolic link so you can't simply copy or move it to other directory. To make link movable create link to file with absolute path. For example:

ln -s /home/guest/client.py incro

Or simply create link directly in your bin directory.

Upvotes: 1

Wayne Foux
Wayne Foux

Reputation: 135

In Linux to make a file executable you will need to set the file with the following command:

chmod +x [filename]

This will make the file executable to root, user, and group owners.

To make the file executable from any directory you will need to make sure that the directory is listed in your PATH.

echo $PATH

will show you which path you should move your file or symbolic link to. There are also ways to add any path to the PATH but you will likely find convention to add your executables to /usr/local/bin. Just validate that it is in your path using the command above.

Upvotes: 1

Barmar
Barmar

Reputation: 781935

Put the link in your bin directory, not the current directory:

ln -s $PWD/client.py ~/bin/incro

You should also have ~/bin in your $PATH so that you can run programs that are in there.

And if the script isn't already executable, add that:

chmod +x client.py

Upvotes: 5

Related Questions