 Continue to look at Daniel Kaufman's question about creating your own commands. Now we've gone over creating scripts, obviously in this series. Let me go ahead and move into my temp directory and I'll use Vim as my text error, but as always use whatever text error you prefer. And I'm going to make a script called my cmd. I'll hit enter and I'm going to start off with a shebang line because this is a bash script. If it's a Python script or some other shell, Perl or something like that, be sure to put the shebang line. It does not matter what we're doing today. It could be a binary executable or some sort of script. This is all the same. I'm going to say echo hello world and then I'll just echo pinging Google and then we will ping Google twice, google.com if I could type today. So we have this file called my cmd which will not run if I try to run it. You can see it says permission denied because we have not given it permission to run. We do that by using change mod plus x. This is to prevent rogue programs from running on your system. No program should be able to run on your system without you giving it permission. But once we make it executable by giving it the plus x sign with change mod, we can then run it with .slash my cmd. As you can see, it prints out our text and then it says pinging Google and pinging Google twice. Great. So we have the .slash and if I mentioned in the past, .slash means your current directory. It's saying run the command in the current directory. This is very important because if I move into another directory, let's say I go to my home directory, I can't type .slash my cmd because there's no file called that in my home directory, at least not one that's executable. And I can't just do my .cmd because there's no system command called that. So how do we make it so we can access this file from anywhere and run it? Now once it's important to note that we do have the .slash saying current directory other operating systems, namely Windows, I think is the only one that does it like this, it will by default run whatever command is in the current directory. So for example, I can type in ifconfig and I get this information here. Now there's certain ifconfig commands or other commands that I might want to run as sudo as far as bringing an interface up or down. Now you want to make sure that you're actually running the command that you think you're running. So for example, let me go back to my temp directory and let me move my my cmd to ifconfig. Now if I type ifconfig, is it going to run the one in the current directory or my system command? In this particular case, since I'm on a Linux system or most Unix and Unix like systems, if I hit enter, it will run the one based on my path directory, which we'll talk about, which is a system-wide thing. So it doesn't use the one in the current directory. Now if I do .slash ifconfig, it's going to run the command that I made, which is completely different. You could trick somebody into running a command by placing a program in a folder and when they go to run it, thinking that they're going to run ifconfig. So I could actually have my script run the basic ifconfig command when it runs, but do other malicious stuff as well. So I could be running it and it seems to be working, but then also I issue it with the pseudo command and it overtakes my system or does some malicious stuff. Requiring the .slash for current directory applications kind of avoids that because I know that I'm running the one in the current directory. Not thinking that I'm running a system one, but actually running the one in the current directory. A little side note, just a security thing, because you get asked a lot, why do I have to do the .slash thing? It's indicating that it's a script in the current directory and it's a much more secure way in my personal opinion than the way Windows does it, which if you don't realize that there's a program in your current directory named that you could be running a command you don't think you're running. But how do I make it? Let me move my current ifconfig script back to my CMD. How do I make it so I can run this from virtually anywhere on my system? Well we have a few options. Now you have your path variable. If I echo dollar sign capital, path, and that is case sensitive, it's going to list where all my executable files are from that are system-wide. So I have this folder, this folder, you can see they're separated by colons here. So I can place this script into one of these folders. For example, most of your executables on your system are going to be in the USR slash bin folder. When you install something with your system using aptitude, aptget, or wherever package manager you use, it's most likely going there. In some places it might go to the Sbin folder or the bin folder. Those are more, how do I say this properly? A lot of those scripts are required for startups and a lot of basic low-level commands. But most other applications you install are going to go here. But we're not installing this application necessarily. This is a custom script. It's different than installing from aptitude, aptget, or wherever package manager you use. Now I could put it in here. That's not really a problem. I could put it in any of these folders. It's just not really proper. USR forward slash local forward slash bin is a place where you should put your own scripts that you've written. Not only is this help just keep things organized and you can differentiate between installed programs and scripts you wrote, but also it makes it very easy if you're going to move to another system and you want to bring all your scripts with you. You can just copy all this folder over to the new system and you'll have all your scripts where if you put them inside this folder, which I'll list out everything in this folder, you can see there's lots and lots of programs in there. And you don't want to copy all those to a new system. You don't need to. So much that I can't even scroll way back up. The list is so long. And that's three columns wide. So we can put the script in forward slash USR local bin. And what that will do is say this is basically a script I created and that all the users can access. Now let's say I want to have my own scripts for this particular user and only this user. Well, I can make a folder, most likely in my home directory so that it would stay private. I'll call it. I'll make a folder called bin. Oh, I already have a folder called bin. Just for this example, I'll create another folder called my bin, just for example. So I can see the into my bin and there's no files here, but I can copy or move my CMD to this folder. And now I can add this to my path. So again, if I echo out dollar sign path, you can see that this folder is not in here. So what I can do is I can say path equals, and I can either put it at the beginning or the end pan, which folder I want to check first and last, but I'll say path colon. And then I'll say home, home, metal, x 123. And then what did I say this was called my bin? Okay, so now if I echo out dollar sign path, you can see that I've added that's the list. And now even if I'm in my temp directory or wherever I am, I can type in my CMD and it will run. And now, again, this variable is temporary. So what I would really want to do, as I mentioned in the previous video is add this to my RC file, whether it's bash RC, or, or Z shell RC for Z shell or whatever shell you're using, you'd want to add this path command here, adding this folder to it, and it would add it for that user. It's only accessible because it's in their home directory if your permissions are proper. So you can have individual commands for different users. So those are your options. Check out your path. And again, there's also a path if you type path on Windows, you'll see what path programs are in, but most programs on a Windows machine, for example, if you install Firefox or Chrome or Microsoft Office, they're not in the path directory. It's very weird. Maybe their path directory is their Windows system and their Windows system 32 folder, maybe a few other things, which is just weird. Anyway, type path, echo dollar sign, capital path, see what folders are set up on your system for your user, and use those or add your own and add it to your RC file for startup. And so that's that's it. I just wanted to explain the difference between that. You can have your own personal ones in your home directory. You can have personal ones for your system under USR local bin, and then your installed programs are either going to go to your Sard bin in most cases, and occasional cases, bin and S bin. And then some cases games will go here like if you install doom, it usually their files will go under those. So yeah, basically, once you create a script, make it executable, just make sure it's in a path directory, a directory that's in your path variable, and you can now call it from anywhere in your system. So I hope you enjoyed the tutorial. I hope you found it useful. And I hope that you have a great day.