0

Found an article saying to use chmod a+x to add execute permission to a file. What is the difference between it and chmod +x? (And is there an easy way to search about these differences in man pages? "a" is too small to meaningfully search the man pages, and reading them throughoutly would take too long).

3
  • 1
    Why does actually learning how something works "take too long"? You're the one who thinks he should be using the shell. – Marc Wilson Mar 15 at 23:08
  • 2
    The answer is in the third paragraph of the manual page, which is cited in the answer. The entire manual page is 127 lines long on my server. "reading them thoroughly would take too long", are you serious? Would you say something like this in a job interview? I am sure that writing your question and reading comments and answers took longer. – berndbausch Mar 16 at 1:38
  • and besides that, the second paragraph starts with "The format of a symbolic mode is...", which should hint at where the answer could be found. – ilkkachu Mar 16 at 9:27
11

From man chmod:

A combination of the letters ugoa controls which users' access to the
file will be changed: the user who owns it (u), other users in the
file's group (g), other users not in the file's group (o), or all users
(a).  If none of these are given, the effect is as if (a) were given,
but bits that are set in the umask are not affected.

Assuming you have the proper permissions,

  • a+x will set all the x bits of the file.

  • +x will set all the x bits of the file that are not present in the umask.

Example:

$ umask
0022       # The group and other write bits are set

$ ls -l
---------- file

$ chmod +x file; ls -l
---x--x--x file

$ chmod +w file; ls -l
--wx--x--x file

$ chmod a+w file; ls -l
--wx-wx-wx file

Searching in manpages

Is there an easy way to search about these differences in man pages? "a" is too small.

Keywords are usually highlighted in manpages, as are the relevant as in the linked manual. Another way would be to use a search with word boundaries by entering /\<a\> in the Less pager (the default pager used by man nowadays). That matches exact words a, so it does not match alone, but it would certainly catch all the indefinite articles a as well in this particular case. We don't have a grammar aware Less yet.

(FelixJN) Is there a way to match bold/highlighted formatting?

If Less is your pager, enter -U. It enables control character displaying. Each letter in a bold (or colored, depending on your settings) word is backspaced and repeated for highlighting (for italics see reference below), so a highlighted ugo will be written as

u^Hug^Hgo^Ho

and therefore searching for /u^Hug^Hgo^Ho matches any highlighted ugo. But those ^H must be entered with Ctrl-VCtrl-H, quite a hurdle.

(FelixJN) man chmod | cat -A does not show anything.

man detects if the output is a terminal and, if not, discards the formatting. Use MAN_KEEP_FORMATTING=y man chmod to force formatting. You can pipe it to your editor where searching is more confortable. For example, in Vim,

MAN_KEEP_FORMATTING=y man chmod | vim -
/u\bug\bgo\bo

Further reading:

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.