Zack
Zack

Reputation: 1575

What are the options with - (dash) on Linux terminal command mean?

I know very many options exist but in a Linux command like

chmod -R 777 user

What does the -R mean, I know how to use a couple of them but all this I have learnt from tutorials hence I don't really know what to search if I want to learn this part of terminal commands. If anyone has any sources that helped them when they were still fresh in terminal commands, I would appreciate.

Upvotes: 0

Views: 4635

Answers (3)

das-g
das-g

Reputation: 9994

Each command has its own set of arguments, its own set of options (which are just special arguments) and its own synopsis. Thus the importance of built-in* resources like manpages (as already mentioned by @michael-coleman and @tripleee in their respective answers) and info pages.

However, there are some conventions, that a lot (but not all!) of commands share. (Some only partially.):

  • Case usually matters.
  • Proper arguments (those not interpreted as options) do not start with a dash (-). They are usually used to tell the program on which file(s) to operate, for which many interactive shells provide tab-completion by default.
    • Notable exception: An isolated single dash (-) is used by many programs instead of an input or output file to denote that standard input (piping something into the program or entering it interactively) or standard output (printing the output on the terminal or piping it somewhere) should be used instead.
  • Options (arguments used as flags (on/off) or as the keys of key-value pairs) come in two forms:
    • Short options start with a single dash, and continue with only a single letter (like the -R in your example). Short options not allowing for option values (see below) can often be chained: -a -R -c can be written shorter as just -aRc.
    • Long options start with two dashes, then one or several words, connected by single dashes, (like chmod's --recursive or git diff's --color-words).
  • Option values denote the values of key-value pairs where the key is an option.
    • Short options allowing a value often must be followed by that value within the same argument, i.e. without any space between them, e.g. ld -lc where -l is the key and c the value.
    • Long options allowing a value often must be followed by that value as the immediately next argument, i.e. with only whitespace between them. Another convention used by many commands is to have an equal sign (=) between option and value (ld --library=c). For some commands, both will work.
  • Subcommands specify what to do if the command has multiple functionalities. For some commands they look like options, for others (e.g. git) they look like proper arguments (the diff part of git diff).

Some of these conventions have even been codified, but there are many (and rather important) commands that don't follow them.

While generally, not only available options, but also the semantic for the 'same' options depends on the specific command, some few options have an agreed-upon semantic: -R almost always means --recursive, indicating that the file to be processed is a directory and all directly and indirectly (in sub-directories) contained files and directories should be processed, too. Off course, this doesn't stop some commands to use -r for that meaning and not knowing about -R, or (probably rarer or more obscure) to use -R for completely different semantics.

*Called 'on-line' before interconnected computers on networks were common. I guess this referred to the 'lines' (cables) between terminals (screen-keyboard combinations) and the actual computers, and was used to contrast electronic from 'off-line' (hardcopy paper) documentation.

Upvotes: 1

tripleee
tripleee

Reputation: 189417

Every U*x system comes with manual pages, and they are easy to find on the web as well.

man chmod documents the chmod command, including its options; man man documents the man command itself, etc.

GNU ships documentation in a system called Info which is less ubiquitous but more featureful (clickable links for cross-references, footnotes, etc). Typically, you will find a brief man page which directs you to Info for the full documentation.

On Linux systems, man intro is a gentler introduction to get you started with the system. (There is no intro command; the man page is simply an introduction to Life in Linux.)

The tutorials you have consulted don't seem very convincing if they failed to mention the existence of standard, high-quality on-line documentation within the system itself.

Upvotes: 1

Michael Coleman
Michael Coleman

Reputation: 3398

the -R flag when used with chmod means: apply recursively. This is a very useful command.

If you want to learn more about the chmod command you can acccess the man page by typing man chmod e.g:

From the chmod man page:

-R, --recursive
change files and directories recursively

So for example say you had a directory mozilla - which had subdirectories and files:

/home/user/mozilla/
├── extensions
│   └── profiles.ini
└── firefox
    └── Crash Reports
        ├── events
        ├── InstallTime20140410211200
        ├── InstallTime20150112203352
        └── InstallTime20150125222008

and you ran the command

chmod -R -v 777 /home/user/mozilla/

The -R flag would would change permissions of all the files and sub-folders contained within the mozilla folder to 777 file permissions.

  • Adding -v flag is just useful for showing you what changes have occurred.

Upvotes: 1

Related Questions