 If you enjoy my tutorials and would like to see more, please think about contributing to my Patreon account at patreon.com forward slash metalx1000. Okay, this is a tutorial on the Android shell, which is basically a Linux shell, a little bit slimmed down, but you're running a Linux kernel and Android is a Linux regardless of what some people say. And once you get a rooted shell, you can do pretty much anything on an Android device you can do on a Linux desktop. But I'm assuming with this tutorial that you already have your device rooted, you know how to log into the shell using ADB, ADB shell, and then you'll have a command prompt like this. I am on my tablet here hooked up through USB and I am logged in as root. Now, first thing you do when you root your device, you're going to want to type in busybox. And busybox is basically to sum it up, it's a shell with a bunch of built-in functionality that you would normally get from external commands. And it's found on pretty much every Linux system, especially smaller devices like routers, modems, TVs, phones, tablets. There's going to be some form of busybox installed on there. But on a lot of, especially Android devices, phones, when you're on busybox to see what commands are available, you probably have about that many. You don't have this many because they put a very slimmed-down version of busybox on there. Search the internet, you can either find a copy of busybox or compile your own, just make sure you get the right one for your type of processor. And you should have all these commands. You'll have basically every tool you'll need. You have Ock, you have Churr Roots, a big one. If you're going to want to Churr Roots, you're going to want to have a full version of busybox installed. You know, Grap, and even a lightweight version of Netcat. It's missing some features, but it's there. Now, when you first do this, some of these things you might try to run, like if I type in IV there, IV starts up, but you may not have that installed. And so you can install busybox so it links things. Otherwise, if you just copy the binary over, you might have to type in busybox and then the command. And if those commands are already on the system, you might still need to type busybox. So here's a quick example of that. I'm in my root directory. If I type in LS, I can see a list of files. If I type in LS-LHA, and the A is for human readable, I hit enter. It says aborting. I don't know what dash A means, but if I type busybox first, it does work. And you can see things are color coded in the version of busybox. So if you try to run a command that is installed and it isn't working like you think it should, try putting the word busybox before it. Because you may not just have things linked that way. Another example would be like DF, which shows you your partitions and their usage. And you can do dash H, which I like to, which again will make it human readable. But it gives you that error, same thing. It doesn't know how to use that. If I type in busybox DF-H, it's going to use the DF that is in busybox. And there you go. We get a human readable. Actually, it looks like the default one does by default give you human readable here. But that's not usually the case. But you can see that they are definitely two different versions of DF. The regular one that's installed to the system and the one that's embedded in busybox. That's enough about busybox. You definitely want to look into busybox more as you're going to be working with any type of ARM devices that run Linux. And now more into actual Android commands. So I'm going to clear the screen here real quick. The first thing we're going to look at is PM, which is Android's package manager. Think of it as like, you know, not really apt to, but more of the, here, let's type in busybox. You can see right here, DPKJG, which is for Debian. It's for installing packages. PM is kind of like that for Android. If you just type PM, it shows you a list of all the commands and options for that command. And so let's say we want to see a list of all the installed packages, all the installed APK files on the computer, on the device. I can type in PM list and I'll say packages. And it will list all the packages that are installed. But it's showing the name of the program itself, the package, not the actual APK. If you're wondering where and what the APK for certain programs are called, same command, PM list, packages and do a dash F. And now it's showing the same thing and the associated files. That's what the F stands for there. So like here is a dot com. So this is the name of the program here and this is the APK file. Most APK files are either under your system app folder or your data app folder, depending on whether usually if it's something you installed or something that came with the device. So that's a quick look at PM. But again, if you type in PM, it will show you a lot of other things, especially you can use it to install packages, reinstall, uninstall, disable, that sort of stuff. Don't spend too much time on that. How do we start a program? So I have my device right here. How do we start a program from the command line here? So again, if I do this, you might think, okay, I run around Firefox. Okay, here this is the name of the program. What if I just type that? No, it's not going to happen. Oh, I'll run the APK. You think that's going to happen? No, it doesn't happen. What you have to do is use the AM command, which I'm going to assume stands for application manager. So AM, again, if you hit enter just like PM, it gives you a little help screen with a list of how to use it, starting services, starting activities, forcing stops, that sort of stuff. So where do you want to start a program? So how do we find what program to start? So what I'm going to do is I am going to start up a program. So here I'll come in here to my applications and I will start up a program here that I wrote for my wife. So once that started, it's started up and now I can exit out of it. There is a log cat, which will cat out a log file for your device. I'm going to use the dash D command or option for that command. And then I'm going to grep. And again, depending on your system, you might have to type in busy box grep for this to work, all depending on how your system set up. And the name of the package. Oh, right. Before I do that, I need to know the name of the package. So I can use PM or since I am running it, I can see right here that it is a phone gap. I used phone gap for it to create that application, which I've done tutorials on in the past. What I'm going to do here is again, I'm going to say log. So I can again, sorry, use PS. You might have to do busy box PS to see what applications are running or I can do PM and, you know, list, whatever like we did earlier. But I'm going to search for all phone gap applications. Since I've already run it, whether it's running right now or not, since I've run it since I started the device, it should be in the log file. So I'm going to say log cat dash D. And I'm going to grep again, you might have to do busy box grep. And I'm just going to type in gap for like phone gap. I think that this is, I'm doing this right. And then I'm going to grep for CMP. I'm going to hit enter and you can see a few things came up right here. I know this is the one because it's called MK inventory. That's why I named the application. I can see it's phone gap. So I know this is the name of the program and this is the activity. So we need to know that. So I'll highlight that and I'm going to type in AM. And I want to start to start an application dash N and then what I just copied from there. So again, I'm using Linux here so I can highlight and just center click to paste you. If you're running on Windows, you might have to right click and say copy. Actually it's, you have to mark. Anyway, I'm assuming you're using Linux highlight center click. Now if I hit start, you can see here that it's starting up that application. There we go. Got the screen a little brighter there. Now, AM does have options to kill applications, but I can just like any other Linux system, say PS. I can go. Okay, there it is. I can say kill all and I can say calm that phone gap that WWW and we'll kill it, but also kill any other applications out of running there built with phone gap. And in this particular case, it restarted. Let me try killing it again. I find that sometimes Android, if you try to kill an application, it try it thinks it crashes and it tries to reopen it. So maybe using AM might be a better option for this, but I usually just use kill all or kill and the process ID. So let me go up and I'll start that application up again. So there we go. It's starting up. I'll type in PS. I can see right here. I know it's this one. I can take the PID and just say kill that process and it kills it. Great. So we have that. We've done so far. We've done all the packages, how to find the name of the package and its activity so that we can start it with AM. Now there's another command. It's using AM. So I can say AM start dash a this time. And I'm going to type in Android dot intent dot action dot view. And what this does is that it will try to, if you're used to using Linux, if you're familiar with the XDG dash open command, and on Windows it would be start and a file. It will try to open up whatever file you try to open up with whatever the default program is. So I'm going to start dash Android intent action view. And I'm going to go dash D and I'm going to give it a file name. I'm going to give it a file colon four slash forward slash and then the full address, full, you know, folder path for a file. And I want to go the mount SD card, which actually the same as forward slash SD card. And in my downloads folder, a file called music dot mp3 and using this here and passing it that it's going to go. So I'm going to go to the mp3 player. What is the default application for an mp3 and we'll open it up in that. Boom. My default application is VLC. So it opened up VLC and it's now playing that mp3. If I do a PS, you can see VLC here. I'm just going to say kill all and kill that, but it did open it up. It is playing the mp3 right now. Here's another example of that. Let's say you want to open up a web page. Same command as before, but instead of saying file, I'm going to say HTTP colon forward slash forward slash films by Chris dot com. And I'm going to hit enter. And this time you see I don't have a default web browser set. Oops, I clicked on the screen and removed it. So you can see it brings up an option. What browser do I want to open up with? I can set a default, but since I don't have a default, it brings up the options and I can click on one of those and open it up. I'm going to not do that right this second because I'm going to show you. Let's say you have Firefox installed and you want to open up a web page with Firefox to open up a web page with Firefox regardless of what the default web browser is. We can use AM. And we're going to say start dash and org dot Mozilla dot Firefox. And of course you have to have Firefox installed for this to work. And it's slightly different if you have the beta version installed because the programs if they're installed at the same time that be named different things. But again, AM start dash and org dot Mozilla dot Firefox dot app and then the name of the website films by Chris dot com. And this time it will bypass the default asking what browser do you want to open up and it doesn't care what the default browser is. It's just going to open up in Firefox because that's what we're starting there. So that's Firefox there. Next we're going to look at where applications store data. So if we do CD data dash forward slash data, this is a folder. And I don't know if this varies from device to device, but all my devices it seems to be here. We can list out and you can see there's other folders in here for pretty much every application. And this is where things are stored. So for example, if I go CD in the data data folder, we're going to go com dot Android providers dot contacts. So this is something that everyone should have because this is built into Android. And I can go into databases in there. Now for list out here, you can see there's a couple of files. They're all database files. I'm not going to show you the contents of this file because it's my contacts. So it has like my email address and pretty much all my contact information. But if you were to head out this file just to see the first few 10 lines of it, you'll see at the very beginning that it says it's a SQLite 3 format. So if you know how to work with those, you can take that file and export information from import information into it. If you really don't know how to work with SQL files and you want to just view the content of it, you can always use the strings command, which is built into my device here as well as pretty much every Linux system. It's something that I would go into more working with binary data. But that will show you all just the non-binary data in there and you can grep through it using grep-a in the file. So just so you know, data, data, so forward slash data, forward slash data, is where the data for all programs is stored if a program stores anything. And I think even if they don't store stuff, there are still settings that are set in there. But that's where all the information is saved. Next, I'm going to show you how to send keys. Sending keys is great for scripting out something that interacts with another program that otherwise might be hard. It's kind of a sloppy way of doing things, but it can be very useful. I'm just going to clear the screen here. And what I'm going to do here is, let's see. We already have Firefox open, but let me start Firefox again. Open up a new tab and I'm going to go to Google.com. So there we go. We're opening up Google.com. By the way, I should have said at the beginning, this tablet here is a really, really cheap tablet. You can get one of these for probably around $75 if not cheaper, brand new. And they are great for doing stuff like this, testing stuff out because you don't really have to worry about screwing you up. And really, especially after your root device, you should have a system backup that as long as you don't mess up your recovery partition, you should always be able to recover from any mistake you make in the shell here. So don't touch your recovery partition once you have it set up. Back things up and you really don't have to worry too much about messing up the system because you can always just image it back over. So anyway, here we are at Google's home page. I'm inside the search bar there. Let's say from the shell, whether it's here I'm logged in through USB, but you can also write shell scripts and use everything I'm showing you here in those shell scripts. But Android has a built-in command called input. And you can do input text and then give it some text. So I'm going to say hello and hit enter. And you can see on the screen here, it types out hello. Now, let me clear that out. And I'm going to do the same thing, but let's say I want a space in the word. So I want two words, four spaces, you're going to use percent s. So if I do hello world, I'll hit enter. And you can see it types out hello world. I'll show you without the percent s there. It will type the first word and then stop there so it didn't get the world part of that. Now, not only can you send strings, but you can also send button presses. So for example, I can do input and instead of text, I'll say key event. And I can send it and I'll try to post in the description of this video. I'll link to all the notes for this tutorial, which I'll also put in a list of all the different key events. One of which is, I don't have my notes right here. Oh, here I have them over here. Okay, three. Okay, so key event number three would be like pressing the home button. So I'll send input key event three and I do that. And it takes me to my home screen. So again, I can open up Firefox and by pressing key event three, it brings me to the home. And there's key events, key codes for the menu button, home, back, power buttons. Another example would be volume buttons. So I can do key event 24, which is volume up. And each time I do that, it goes up a little bit just as if I was pressing the volume buttons on the side of the device. And key event 25 is volume down. So I can do that a few times and you can see the volume is going down. Now, again, we are at a shell just like any other Linux system. So if I wanted to, I can create a loop. I can say four I in and I can do the back ticks here. And again, depending on how you busy box up, you might have to say busy box, SEQ. If you have it's actually installed and not just binary there, you should be able to just type SEQ. And I'll just say one through 10. So this would be creating a for loop, counting from one to 10. And what I'm going to do is each time I'm going to do an input key event. And okay, so my SD card for the camera recording tablet just got full. And I'm not really sure where my other cards are. So you won't see the tablet for the rest of the tutorial. So you just have to take my word on this. But what we were saying is just like any other shell, I can say four I. So I'm creating a for loop with a variable I in. And again, this is, like I said, I hope that you know how the shell works somewhat on a regular Linux or Unix system for I in. And I'm creating a loop loops from one to 10. And again, you might have to use busy box here. You might have to type it like this depending on how you have busy box set up on your system. I'm going to do event and I'm going to say 24. Just so I have some output on my terminal screen here. I'm going to say echo and 24 is volume up. So I'll say volume up and we'll say done. So right now I'll hit enter and it's a little a few seconds delayed. But boom, my volume just went up as if I hit the button, the volume button up 10 times. And I can do the same thing with down again 25 is down. So again, right now the volume is almost fully up and now it's going to go. There we go. Again, there's a slight delay when you're doing these key event input sends. But you could definitely put this into a shell script on the device and run those shell scripts and send keys to other programs. You can open up application and send keys. I also want to point out, I can't show you because my camera stopped recording. But if you're ever at your home screen and you start typing something on a keyboard, it will automatically start doing a Google search for you. So I could do the key event three for home and then the, it just gave me the output for the last command. So I can do key event three, which would bring me to my home screen and then send a text like so. And right now my tablet's now doing a Google search for Hello World. And again, there's also keys for sending the enter key, I believe. Let me look at the notes here. Clear camera. Yep, enter 66 is enter. So I should be able to do key event 66. And now it's trying to open up a browser. It's asking you which browser. So yes, so you could create a shell script with these three commands that when that shell scripts run, it would basically do a Google search for Hello World. And that's it. So that's it for this tutorial. We went over a lot and there's still a lot you can do. Again, I tried to look specifically at Android specific commands other than that with busy box installed. You got a fairly powerful shell. And then if you have a Debian or other Linux distro arm image, you can mount that and churn it into it, in which case you have a fully functional Linux operating system. Now, of course, the Linux or the Android interface doesn't support, you know, GTK or many other GUI interfaces. So a lot of your GUI applications won't run in the Android interface, but theoretically, and we'll look at this a little bit more in the coming weeks. You can kill the Android interface and start up Xorg as well as do other things with the frame buffer device. And if you've never played with the frame buffer on a Linux system, you can have lots of fun with it. And so those are things we're going to look at in the coming weeks. Again, went over a lot here. Hopefully I'll remember to put a link in the description of this video to the notes that I read to myself while I was doing this. So you'll be able to see all those commands easily. And again, I thank you for watching. Please visit FilmsByChris.com. That's Chris at the K. There should be a link in the description. And as always, I hope that you have a great day. So even though you have that original server, you may have another server here and here that you can download from. And Axel allows you to do that too. You have the same file on multiple servers.