Header Banner
Null Byte Logo
Null Byte
wonderhowto.mark.png
Cyber Weapons Lab Forum Metasploit Basics Facebook Hacks Password Cracking Top Wi-Fi Adapters Wi-Fi Hacking Linux Basics Mr. Robot Hacks Hack Like a Pro Forensics Recon Social Engineering Networking Basics Antivirus Evasion Spy Tactics MitM Advice from a Hacker

How to Create Custom Commands in Kali Linux

Aug 14, 2015 02:27 AM
Aug 14, 2015 02:43 AM
Terminal command prompt interface

When attempting to run a script, it can be rather inconvenient to have to locate the script, and run it time and time again. What if there were a way to run a script from anywhere. Well that's what we'll be doing today. This can be useful for any scripts you use frequently, it can save you time by removing the need to locate and execute.

Create a Script

In this step we'll be creating a script that we'll use as an example.

Python code snippet for a quiz question about learning programming at Null Byte.

Here we set our interpreter path and and ask the user a simple question.

Save the Script

We need to save the script without an extension so we don't have to use the "python FILENAME.py" method.

File saving dialog window with a focus on naming a file.

We save our script as "ask" with no extensions in the Scripts folder on our Desktop.

Give the Script Execute Permission

To be able to run the script we need to give it execute permission...

Terminal command line output showing directory contents with details.

Here we can see that the script does not have execute permissions, yet...

Command line interface showing a file permission change command.

We run the above command to give our script execute permission, this will enable us to run the script without the "python FILENAME.py" method. Now if we check the permissions again we should see the name appear in green as it is now executable...

Terminal command output showing directory contents with files named "ask" and "Python."

We can see in the about result that that script now has the needed permissions, on to the next step!

Move the Script to the Proper Location

At the moment we need to be in the scripts directory in order to execute it. In order to execute it from anywhere we'll need to move it to the proper place.

How to Create Custom Commands in Kali Linux

We copy the script to the "/bin" directory. This is where commands for our system reside. If we look in the "/bin" directory, we should be able to see our script.

Terminal command output displaying various commands and their attributes.

Now we should be able to run this script from anywhere by simply entering "ask" as a command.

Test the New Command

Since we've created this new command, it's only fitting that we give it a test. In order to test it, we'll enter "ask" as a command from any directory...

Terminal screen displaying a question about the best place to learn hacking.

We've run the new "ask" command from our home directory and it works! We've ran our script from a different directory! But we can't just leave it's question unanswered, let's answer it honestly and see if it agrees.

Terminal window showing a conversation about the best place to learn hacking, highlighting Null-Byte as the recommended site.

There we have it! Now we're able to run this script from any directory, effectively creating a new command. This works for any script you have, you can use this to do a multitude of things. You can make a bash script to execute a set of commands automatically from anywhere, or you can do what we did here today and create a script that actually has some use and execute it from any directory.

Feedback!

Let me know what you think! If you have any questions comment them down below and I'm sure they'll be answered!

Thank you for reading!

-Defalt

You already know how to use your phone. With Gadget Hacks' newsletter, we'll show you how to master it. Each week, we explore features, hidden tools, and advanced settings that give you more control over iOS and Android than most users even know exists.

Sign up for Gadget Hacks Weekly and start unlocking your phone's full potential.

Related Articles

Comments

No Comments Exist

Be the first, drop a comment!