So don't you hate it when you have to type "./" before an executable's name in the linux terminal before it will execute?
Probably not.
Anyway, it can be fun to make it so you dont have to type './' before an executable's name.
It has other benefits too.
For example, if you ever compile with gcc you just type this:
gcc hello.c
And somehow it works right?
Well all those commands like mkdir and cd are just executables that are in a special folder that makes them the way they are.
mkdir
cd
What is this folder?
Navigate to /usr/bin/ on your machine (im using kubuntu).
/usr/bin/
Ok that is the folder.
But how can we do things in here?
Create a file in your home directory called hello.c.
hello.c
$ touch hello.c
Then open it up with your favorite text editor and type this in it:
#include "stdio.h" int main() { printf("You made your own command!"); return 0; }
Then save it.
Then compile with this command.
gcc -o hello hello.c
Then copy the executable it creates to the special folder with this command.
sudo ln -s /path/to/your/exe /usr/local/bin/hello
Note that the folder is /usr/local/bin/ this is the folder for user created binaries whilst /usr/bin/ is for system binaries.And then if you type
/usr/local/bin/
hello
It will run the executable.
If you run the command
sudo ln -s /path/to/your/file /usr/local/bin/nameOfNewCommand
With the old command nameOfNewCommand was hello.
nameOfNewCommand
And there ya go!
Thank you for reading and please consider an upvote. (I just joined repl.it yesterday and I am in love with the tutorials feature!)
Nah.
What you'll do is add ~/.local/bin to your $PATH and symlink ~/bin to ~/.local/bin and mv bin ~/bin
mv bin ~/bin
Yes, that is a good way to go about things. This way works too :-) @CodeLongAndPros
Adding a command (global executable) to linux
Hey.
So don't you hate it when you have to type "./" before an executable's name in the linux terminal before it will execute?
Probably not.
Anyway, it can be fun to make it so you dont have to type './' before an executable's name.
It has other benefits too.
For example, if you ever compile with gcc you just type this:
And somehow it works right?
Well all those commands like
mkdir
andcd
are just executables that are in a special folder that makes them the way they are.What is this folder?
The folder
Navigate to
/usr/bin/
on your machine (im using kubuntu).Ok that is the folder.
But how can we do things in here?
Create a file in your home directory called
hello.c
.Then open it up with your favorite text editor and type this in it:
Then save it.
Then compile with this command.
Then copy the executable it creates to the special folder with this command.
Note that the folder is
/usr/local/bin/
this is the folder for user created binaries whilst/usr/bin/
is for system binaries.And then if you type
It will run the executable.
Further Development With This
If you run the command
With the old command
nameOfNewCommand
washello
.And there ya go!
Thank you for reading and please consider an upvote. (I just joined repl.it yesterday and I am in love with the tutorials feature!)
Nah.
What you'll do is add ~/.local/bin to your $PATH and symlink ~/bin to ~/.local/bin and
mv bin ~/bin
Yes, that is a good way to go about things. This way works too :-) @CodeLongAndPros