Other Stuffs

Make your own Commands

Sometime you may be thinking to make your own commands just like  “ls” “cd” “cat”…. in shell (Linux) or “dir” “cp” …… in Command Prompt (Windows) and good thing is you can do it easily.

Way for windows

1.You will need c/c++ compiler.
here I have used turbo c++.
2.Now type the code in editor window. This program is what your command will do on execution.
3.Now compile and run c/c++ code and you are almost done with it.
Code should be error free.
4.Now you have to locate the executable file created by compiler.
In turbo c it is at location:
TurboC/Disk/Source.
5.Name of the executable will be same as the name of c- file name.
eg.if your file is noname00.c
then after compiling executable will be noname00.exe
Now just copy this executable to C:/windows/system32(or 64)/
and you are done……..

If you are unable to copy executable to system32 then follow the steps:

Now you have to make a folder (Anywhere)
I’ve made folder My_Binaries at C:\.
Move your executable file to this path.

Now you have to change Environmental variable.

For this purpous goto My Computer>Right Click in Blank space > Properties>Advanced Setting(Left Panel)>Environmental variable>Scroll down in bottom Most Panel to PATH>Double click>Add path of your folder to it

Now path must look like this>>>
C:/system32/;some/another/path(s)/;C:/My_Binaries/

Now try the command in cmd like this:
Open command prompt>Type “your executable name”(Without quotes).>Hit Enter.
e.g.noname00
***Your OUTPUT here***

Way for Linux

In Linux OS you will need gcc/g++ compiler installed.
And root password too.
If you don’t have root password you can’t embed your command into system.

steps:
1.Write a simple c program. This will be your command.
2.Now compile the program like this
in shell type:
gcc your_program.c -o your_program
./your_program

your_program will replace name of your program.

3.Now just copy the executable to /usr/bin(requires root privileges).

4.Now try your command in shell.
name of command will be same as your executable (which we just copied to /usr/bin).
5.You even can copy the executable to /usr/bin or/bin folder.
6.If you want your own folder then create a folder and give its path in the file:
/etc/environment

e.g.
contents of etc/environment before editing:
“/bin:/usr/bin/:/usr/sbin/……………..”
after editing:
“/bin:/usr/bin/:/usr/sbin/……………..:/your/folder/path/here/:”

If you do no have root privileges then as mentioned above make your folder with your executables in it and then type this in shell.

expr $PATH=$PATH:/your/path/here:

but each new instance of shell will reset path to original value…
hence this is temporary action.

For Android
*You will need C4droid to compile C code on Android.
Now Open C4droid and type c-code in it.

When you complete typing compile and run it.

After that browse to following location:
/data/data/com.n0n3m4.droidc/files/
(requires root permission)
Now your current source code will be in temp.c file and executable binary file will be named temp.Now copy temp file and paste to the /bin/ or /system/xbin/
Rename it and the name will be your command’s name.
Done!!
Open Terminal Emulator and try it!!!
and please let me know if you have any doubt

ENJOY!
Do some experiments on your own……..

Problem?
Comment below…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s