The syntax of commands in UNIX

As you know the commands must be typed following certain rules, or otherwise discarded by the interpreter.

The syntax of commands in UNIX | Websites Management | As you know the commands must be typed following certain rules, or otherwise discarded by the interpreter

Most of your work with UNIX will be carried out by entering orders.

As you know, the orders must be typed following certain rules, or otherwise they will be discarded by the interpreter.

In principle each order can follow its own format for the specification of the arguments, but in UNIX all of them follow an agreement, which makes the life of the user much easier.

Although you will normally use the command line to type an order every time you should know that it can contain several, simply separating them by a semicolon (;). Let's see an example:

$date; uptime; cal 2015

In fact, this is a shell property. You must bear in mind that it is the shell or command interpreter who processes the orders you enter and then launches the appropriate programs.

To process an order, UNIX searches for and executes a program with the name of the order that is stored somewhere in the file system.

Usually the order is followed additionally by other information: the arguments.

The arguments are separated from the order and from each other by blanks. There are two types of arguments: options and parameters.

The first ones consist of a hyphen (-) and a letter. The parameters go below. The parameters usually contain all kinds of information that the order needs to carry out its task, such as the files on which it must operate.

The options modify the way you do it. For example:

$sort -u -n data.txt

This instruction sorts the contents of the data.txt file, which has been passed to it as a parameter.

The -u option causes repeated lines to be deleted in the file, and -n selects sorting according to a numeric field.

IMPORTANT: Both when typing the commands and their options and parameters, you must bear in mind that UNIX distinguishes uppercase letters from lowercase. According to this, the sort command is not the same as SORT or Sort, nor are the -R and -r options equivalent.

In general, parameters are considered all those arguments from the first that does not begin with a hyphen (-). For example, in the order:

$ls -l data.txt -g

The argument is not an option of the order, since it is located after a parameter, so it is also a parameter. The ls command shows some type of information about a file or directory.

If you wanted to get this data about a file whose name starts with a hyphen, for example '-l', you could try typing something like:

$ls -l

However, the ls command would interpret the indicated argument as an option, since it starts with a dash.

Obviously, the quickest solution might be to not use the script as part of the name of a file. There is another alternative:

$ls - -l

The argument '-' inserted before the file name indicates to ls that there will be no more options and that the rest of the arguments of the order will be parameters.

If you have to type many options for an order it can be very uncomfortable to have to enter the script and the space each time. For example:

$ls -l -F -a -i -R data

You can combine all the options of a letter in a single argument, placing a hyphen followed by all the options you want to use. The previous example would look like this:

$ls -lFair data

Which is much more compact.

GNU programs have, on occasion, options of more than one letter. In this case they are usually preceded by two hyphens (-) instead of one, and can not be combined in a single argument.

For example, using the GNU version of the ls command (the one available in Linux) you could type:

$ls –classifi –almost-all

Not all the commands follow these agreements, but most, and above all, the standard UNIX commands.

🤖

ChatGPT Free
Ask questions on any topic

CITE ARTICLE


For homework, research, thesis, books, magazines, blogs or academic articles

APA Format Reference:

Delgado, Hugo. (2019).
The syntax of commands in UNIX.
Retrieved Nov 11, 2024, from
https://disenowebakus.net/en/unix-commands-syntax

Participates!

Share it with your friends in Social Networks!

Professor at the University of Guadalajara

Hugo Delgado Desarrollador y Diseñador Web en Puerto Vallarta

Professional in Web Development and SEO Positioning for more than 10 continuous years.
We have more than 200 certificates and recognitions in the Academic and Professional trajectory, including diploma certificates certified by Google.

CONTINUE LEARNING

IT ALSO DESERVES TO PAY TO VISIT:

Not finding what you need?

Use our internal search to discover more information
Related content:

Would you like to learn more about Web Design?

Meet all the courses and tutorials that we have for you completely free
Learn Web Design
 

Leave your Comment

SPONSOR

Your business can also appear here. More information