• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root terminal commands....

Great!

I have a couple of questions though...
1. In the shell functions section, you mention $#, what's that? Is it some linux variable, it seems to be determining if any text is typed (a 'yes' 'no' type of variable), but I am not sure if that's it..?
2. with the aliases, if you have df set for df -h, what would you type if you wanted to use df with a different argument? Just curious with this one.
3. What is PS1? Is that ps from the post above (process id or something).

This is becoming possibly the most helpful thread on the forum next to rooting for dummies, but probably is for a bit more of a niche audience.

Anyway, great stuff.
 
Great!

I have a couple of questions though...
1. In the shell functions section, you mention $#, what's that? Is it some linux variable, it seems to be determining if any text is typed (a 'yes' 'no' type of variable), but I am not sure if that's it..?
2. with the aliases, if you have df set for df -h, what would you type if you wanted to use df with a different argument? Just curious with this one.
3. What is PS1? Is that ps from the post above (process id or something).

This is becoming possibly the most helpful thread on the forum next to rooting for dummies, but probably is for a bit more of a niche audience.

Anyway, great stuff.

1) $# is the number of arguments given when a function is called. So, the function is hs. When I run hs, if I didn't supply any arguments to the function, $# is 0, meaning there were no arguments. If that is the case, it simply runs the history command. Using else, meaning $# (or the number of arguments) isn't 0 (it must be some number greater than it, then), then that means I supplied an argument. If I did, then it runs history|grep whateverargument. That command will run history, then search for the command I'm looking for.

2) Options can usually be run together, either separately or individually. Depending on the command, some options can be run together and some can't. -h is a pretty generic option, and can be run with basically all other options. So, If I wanted to run df -k (I'll let you lookup what that does ;)), I can still just run df -k using my alias, and it'll expand it to df -h -k, which is still a perfectly valid command.

3) PS1 is the variable that defines what your prompt looks like. It supports a few different escape characters for various information (\w is your current directory, for example). If you want to see what I mean, type this from the command line:

OPS1=$PS1
PS1="asdfasdf"
PS1=$OPS1

And you'll see that your prompt will change to that nonsense string in between. You can change this as much as you like while running bash, but it's generally accepted that you should just set it once in your bashrc file.
 
Someone has been busy lol. Bashrc file is too handy I don't even want to use it :), thanks. Love the highlighted prompt :)
 
Okay, here's some more use(ful/less) information. It can be a real pain to type all these commands out in the terminal on your phone. Soft keyboards have never been as usable as a real keyboard is. The terminal is meant to save you time, and it really can, but not if you're fumbling to type the right thing. If you intend on typing in a few commands here and there, taking the time to set up adb and connect your phone is also a pain. It does, however, allow you to run commands from your computer. As I said, though, it's kind of a pain.

A nice solution is to set up ssh. Ssh is a secure, remote shell. It means you interact with your phone at the shell just like you do locally, but it's both remote (from any other host that can run the client) and it's secure (encrypted). So, you'll need two things to do this. You'll need an ssh server running on your phone, for starters. There is a way to do it for free, but if you want to save yourself the trouble, and want to have a nice little toggle widget, go grab quicksshd from the market. It's very easy to set up. Open it up, and set a password where prompted. Now, you need a ssh client on your computer. The standard for windows users is putty. You can google it. Go ahead and download that. Open it up, and type in the IP address of your phone. It's a lot faster and easier if you're on wifi, but it will work over 3g. Go ahead and connect, and you will be prompted for your username and password. Just type in root for the username, and then type in the password you set in quicksshd. By default, you'll be in sh, again.

There is a nice benefit to this, though. Quicksshd will set its path in /data/data/whateveritis as your home directory. So, right when you start ssh, run this command:

cp /sdcard/.bashrc ./

That will copy /sdcard/.bashrc to the current directory (remember "." is the current directory, and a directory as the destination for cp will just copy the file to that directory.). Now just need to make it launch bash rather than sh when you start. If you close your session, then go back to putty settings, select "SSH" under connection. For remote command, you can just type "bash" without quotes. Save that profile, and every time you run it, it will launch bash, and which will load your bashrc out of the quicksshd homedir.

Now that you have ssh running with bash, you'll see that it looks just like it did from your phone, with the same prompt and everything. You can now interact with your phone just like you can locally. This is very useful for a number of reasons beyond just making it easy to type commands.

So, it is much faster to do this over wifi, but it can still be done over 3g. That being said, if you decide to leave quicksshd running, that means you can ssh into your phone from where ever you are. There is one problem with this - your IP address on 3g will change every single time you disconnect/reconnect. The solution is to use dyndns. I'm going to way oversimplify this because you can read about it elsewhere, but DNS is basically a map of domain names and IP addresses. When you use a web browser, you're typing in a domain name, which is later mapped to an IP address. Well, your IP address always changes, but you can have a public facing dns record for that constantly changing IP address by using this app. Create an account with dyndns, configure the app to use it, and you will always be able to access your phone via ssh by connecting to that same dyndns domain that you create. Now that I'm thinking about it, novox did an excellent write up about it in a thread some time ago. If you search for that, you can find a little more detail on it.
 
Someone has been busy lol. Bashrc file is too handy I don't even want to use it :), thanks. Love the highlighted prompt :)

Hehe, yeah, this is what happens when I get bored. So, did you actually try it out? Did it work ok? Before tonight, I never had anyone else actually try and use that file.
 
1) $# is the number of arguments given when a function is called. So, the function is hs. When I run hs, if I didn't supply any arguments to the function, $# is 0, meaning there were no arguments. If that is the case, it simply runs the history command. Using else, meaning $# (or the number of arguments) isn't 0 (it must be some number greater than it, then), then that means I supplied an argument. If I did, then it runs history|grep whateverargument. That command will run history, then search for the command I'm looking for.

2) Options can usually be run together, either separately or individually. Depending on the command, some options can be run together and some can't. -h is a pretty generic option, and can be run with basically all other options. So, If I wanted to run df -k (I'll let you lookup what that does ;)), I can still just run df -k using my alias, and it'll expand it to df -h -k, which is still a perfectly valid command.

3) PS1 is the variable that defines what your prompt looks like. It supports a few different escape characters for various information (\w is your current directory, for example). If you want to see what I mean, type this from the command line:

OPS1=$PS1
PS1="asdfasdf"
PS1=$OPS1

And you'll see that your prompt will change to that nonsense string in between. You can change this as much as you like while running bash, but it's generally accepted that you should just set it once in your bashrc file.

Thanks!

As for df -k, googling it, gives some weird results. And of course, after a few minutes of searching, I decided that the man file was just a better way (and my VM will probably boot before the page loads)

So, if I understand it right, -h makes it readable (1k vs 1024) and -k sets it to use 1K as the human readable value? The man file says this:

-k like --block-size=1K


COME ON!

Anyways thanks again. It's amazing all the info floating around this post.
 
Thanks!

As for df -k, googling it, gives some weird results. And of course, after a few minutes of searching, I decided that the man file was just a better way (and my VM will probably boot before the page loads)

So, if I understand it right, -h makes it readable (1k vs 1024) and -k sets it to use 1K as the human readable value? The man file says this:

-k like --block-size=1K

COME ON!

Anyways thanks again. It's amazing all the info floating around this post.

Hehe, sorry, that was kind of a trick question. -k is kind of a weird option. Let's try a slightly better example. I have du aliased to du -h, which will do the same, but show human readable format. du -s is used to show the sum total of a directory given as an argument. I can run du -s, with du as my alias, and it expands to du -h -s, which is a valid command.
 
Yeah working great so far friend. Appreciate it.

Cool :). If I add anything new or make any changes, I'll be sure to upload the new version. I'm sure you'll notice right away how much more usable the terminal is now that you can see your current path, etc.
 
Cool :). If I add anything new or make any changes, I'll be sure to upload the new version. I'm sure you'll notice right away how much more usable the terminal is now that you can see your current path, etc.


Yeah probably double my terminal usage :)
 
Hehe, sorry, that was kind of a trick question. -k is kind of a weird option. Let's try a slightly better example. I have du aliased to du -h, which will do the same, but show human readable format. du -s is used to show the sum total of a directory given as an argument. I can run du -s, with du as my alias, and it expands to du -h -s, which is a valid command.

Ahh, thanks. (but what does -k actually do?)

So, my bash in located in /system/xbin/ will that be a problem? I changed the preferences command shell for /system/xbin/bash --rcfile /sdcard/.bashrc but I get an error

could not load needed library 'libncurses.so' for /system/xbin/bash ... cannot link executable

any suggestions?
 
Ahh, thanks. (but what does -k actually do?)

So, my bash in located in /system/xbin/ will that be a problem? I changed the preferences command shell for /system/xbin/bash --rcfile /sdcard/.bashrc but I get an error

could not load needed library 'libncurses.so' for /system/xbin/bash ... cannot link executable

any suggestions?

What ROM is that? I can't promise it will work with all ROMs/setups.
 
I'm using MIUI, but I am really considering going back to myn's, and if I do that in the next day or so I'll try it again.

How would I go about installing the libncurses.so ? I'm guessing apt-get is a no go?
 
Would another rom have that lib you think? I've got dial up, so these downloads kill me. Or maybe a Nandroid... I'll check out some nandroids....
 
Here I'll give you mine... gimme a sec... dial up what the eff? :)

Yeah, and you'd think I must live in the swamps of Louisiana or something, but I don't. I guess it's just lucky, or retro. It's the trendy retro... lol.

I think I'm just gonna flash a new rom (obviously one I downloaded via wifi ), I could use a change. Maybe kings ultra froyo or mikfroyo 4.5. I could really use a change, but I will be gabbing out that music app from miui...
 
Back
Top Bottom