LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Creating a new linux command (http://www.linuxquestions.org/questions/programming-9/creating-a-new-linux-command-4175445798/)

linkaran 01-16-2013 01:52 AM

Creating a new linux command
 
I have created a new system call for which i need to also create a command at user level so that i can use the terminal to execute the system call.But I am not sure what steps to follow for creating a command like,say 'reboot' of my own.Please give any suggestions regarding the same.

chrism01 01-16-2013 02:19 AM

You need to create a program in /usr/local/bin or /usr/local/sbin, depending on exactly what it does.

jpollard 01-16-2013 07:21 AM

A "command" is no different than any other program.

The only purpose of putting it in /usr/local/bin or sbin (or any where specific) is for sharing purposes.

If you are the only user of the command, put it anywhere you want.

shivaa 01-16-2013 08:44 AM

Keep the call i.e. program file wherever it is and add it's absolute path to every user's PATH variable. User then can run your program directly from any location.

For bash shell you can add as:
Code:

~$ export PATH=$PATH:/path/to/program

RaviTezu 01-16-2013 08:55 AM

& Make sure you have the permissions to run it!

rtmistler 01-16-2013 03:48 PM

I would put it in /usr/local/bin or /usr/local/sbin but do so to make the owner and group both "root" and make the permissions be 755

Code:

# cp new-command /usr/local/bin/.
# cd /usr/local/bin
# chown root new-command
# chgrp root new-command
# chmod 755 new-command

Other things to cross check:

- Verify that /usr/local/bin or /usr/local/sbin are in your path; they should be.
- Perform "ls -l" of your /usr/local/bin or /usr/local/sbin directory where you intend to place the new command and see for yourself what the normal owners, groups, and permissions are. Be cautious that symbolic links will likely have different permissions and further many times symbolic links are pointing to a revision based executable in the same directory; for instance gimp on my system points to an executable for gimp-2.6 which are both in the /usr/bin directory.

You may ask "Why /usr/local versus /usr/bin or merely /bin?" The reason is more historic and conventions versus technical; however the historic convention was technical. On server based Unix systems, the partition /usr/local was truly local to the user and other partitions were server based. Therefore when you had a script or program to be shared with your team or the rest of your company or peers there were other partitions where you placed this shared data so that they could try it an the main system /bin or /usr/bin directories were controlled by the system administrator who would place your executable in those partitions if it was deemed to be acceptable, or if you weren't in their bad graces for some reason.

suicidaleggroll 01-16-2013 03:59 PM

run
Code:

echo $PATH
and put your program in any of the directories that are in that list (some will obviously be more "suitable" than others, such as /usr/local/bin or /home/user/bin, but any of them would technically work). Or you can put it anywhere you want and simply add the directory that it's in to your PATH by modifying your ~/.bashrc (or similar file for whatever shell you use).

Tinkster 01-16-2013 07:07 PM

Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.

Balvinder87 01-21-2013 05:22 AM

you can write a simple version of cp command this command will simply copy the contents of one file into another.
if you need the code tell me first try it yourself?

NevemTeve 01-21-2013 07:47 AM

Dear OP, if you were able to create a new system-call in the linux kernel, then most likely you are also able to build an executable program...


All times are GMT -5. The time now is 08:16 AM.