0

Hi everyone i'm learning linux now and i'd like to know what can be defined as a complex command on linux and how to program(apply) it on the terminal i know simple commands like ls, cd, mkdir and lots of others.Also can u tell me please how can i program my own new command on linux.and I'm not so clear on the difference between sudo commands and user commands.Thanks.

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by JasonHippy
0

Hello,

You need to look into a book on the shell (bash shell programming) and the difference between commands with and without sudo is that sudo executes the command as root.

0

Issuing a command prefixed with sudo means that you're issuing the command as the 'root' user. (Which gives you the proper privileges to invoke the command.)

E.g. You won't be able to write to any files in the root file system '/' /(/etc /usr) unless you have root access. This is what makes linux so secure compared to windows.

0

Typing commands on linux is like running programs. For example: ls is input the same way as gedit. You can run your scripts files by making it executible with chmod +x, which then behaves like a command if I correctly understand what you're asking.

1

One thing you need to bear in mind is that all of the commands available in BASH (and the various other shells in Linux) are programs or scripts that reside in various system folders specified in the $PATH environment variable.

The /bin/ directory typically contains programs/commands that are ran at boot-time.
The /usr/bin/ directory is the main system folder for user-space programs/commands.

Whenever you type a command in Bash you are simply running one or more of these programs and passing various parameters. So for example, the command ls -l calls the system program 'ls' (which lists the contents of a directory) and passes the parameter '-l' which gives more detailed information about the listed files.

There are lots of different ways of creating your own custom commands in Linux. And how you do it depends on how far you want to take things!

Creating your own commands could be as simple as using the pipe or redirection operators to string together several calls to various 'simple' system commands/programs(using the output from one command as inputs to others, or to redirect output from a program into a file).
Take a look at this link:
http://www.tuxfiles.org/linuxhelp/iodirection.html

Or you could write a script to perform a specific task. This could be done by writing a shell-script or by using some other scripting language (perl, python, lua etc).
Here's a link to one of the many shell-scripting tutorials out there:
http://www.freeos.com/guides/lsst/
There are tutorials all over the web for Perl, Lua, Python etc. too!

You could even create an alias which will execute a particular script, or a command/program, or even a string of commands/programs using pipes and redirection. Typically aliases only last for a single terminal session, but you can create a persistent alias (that will be available every time you open a terminal) by adding it to your .bashrc file (a system file you'd need to edit as root)
To see more on aliases:
http://linuxreviews.org/quicktips/alias/

Or if you really wanted, you could use a full-fat programming language like C or C++ to create your own programs. After building a program of your own, you could either copy the executable to a system folder (/usr/bin/ would be a good bet), or add the path to your program to your systems $PATH environment variable. Or if your program is somewhere in your home directory and you only want it to be for your own use, you could just create a persistent alias in your .bashrc file to allow you to run it without having to specify the full path to the program.

With regards to use of sudo, see nonshatters reply.
Also you might want to check this out:
http://linux.about.com/od/commands/l/blcmdl8_sudo.htm

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.