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.
|
You need to create a program in /usr/local/bin or /usr/local/sbin, depending on exactly what it does.
|
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. |
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 |
& Make sure you have the permissions to run it!
|
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/. - 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. |
run
Code:
echo $PATH |
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
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? |
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 11:56 PM. |