LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-16-2013, 12:52 AM   #1
linkaran
LQ Newbie
 
Registered: Aug 2012
Posts: 17

Rep: Reputation: Disabled
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.
 
Old 01-16-2013, 01:19 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
You need to create a program in /usr/local/bin or /usr/local/sbin, depending on exactly what it does.
 
Old 01-16-2013, 06:21 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 2,232

Rep: Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577
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.
 
Old 01-16-2013, 07:44 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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
 
Old 01-16-2013, 07:55 AM   #5
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
& Make sure you have the permissions to run it!
 
Old 01-16-2013, 02:48 PM   #6
rtmistler
Senior Member
 
Registered: Mar 2011
Location: Milford, MA. USA
Distribution: Angstrom, Debian, Ubuntu, MINT
Posts: 1,193
Blog Entries: 7

Rep: Reputation: 487Reputation: 487Reputation: 487Reputation: 487Reputation: 487
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.
 
Old 01-16-2013, 02:59 PM   #7
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,954

Rep: Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029
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).

Last edited by suicidaleggroll; 01-16-2013 at 03:00 PM.
 
Old 01-16-2013, 06:07 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,983
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 01-21-2013, 04:22 AM   #9
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Rep: Reputation: Disabled
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?
 
Old 01-21-2013, 06:47 AM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,807

Rep: Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501
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...
 
  


Reply

Tags
command, terminal


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sometime mkdir command in linux creating directory without time stamp suresh_rtp Linux - General 6 08-03-2011 01:08 AM
Creating a Linux Terminal Command From Scratch realpockets Linux - General 9 01-18-2011 10:15 AM
Creating your own command in Linux LinuxMania_TJ Linux - Newbie 10 01-16-2011 09:00 PM
Creating Command Alias? carlosinfl Linux - General 3 07-14-2007 05:32 PM


All times are GMT -5. The time now is 03:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration