Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-16-2013, 12:52 AM   #1
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
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
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,696

Rep: Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261
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
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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:
~$ export PATH=$PATH:/path/to/program
Old 01-16-2013, 07:55 AM   #5
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
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,256
Blog Entries: 12

Rep: Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862
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

# 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
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,481

Rep: Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089
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
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
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
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,158

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


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 02:04 AM.

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