Function: set-file-modes

set-file-modes is an interactive function defined in fileio.c.

Signature

(set-file-modes FILENAME MODE &optional FLAG)

Documentation

Set mode bits of file named FILENAME to MODE (an integer).

Only the 12 low bits of MODE are used. If optional FLAG is nofollow, do not follow FILENAME if it is a symbolic link.

Interactively, prompt for FILENAME, and read MODE with read-file-modes, which accepts symbolic notation, like the chmod command from GNU Coreutils.

Other relevant functions are documented in the file group.

View in manual

Probably introduced at or before Emacs version 1.5.

Key Bindings

Shortdoc

;; file
(set-file-modes "/tmp/foo" #o644)

Aliases

tramp-compat-set-file-modes chmod

Source Code

// Defined in /usr/src/emacs/src/fileio.c
{
  Lisp_Object encoded;

  CHECK_FIXNUM (mode);
  int nofollow = symlink_nofollow_flag (flag);
  Lisp_Object absname = Fexpand_file_name (filename,
					   BVAR (current_buffer, directory));

  /* If the file name has special constructs in it,
     call the corresponding file name handler.  */
  Lisp_Object handler = Ffind_file_name_handler (absname, Qset_file_modes);
  if (!NILP (handler))
    return call4 (handler, Qset_file_modes, absname, mode, flag);

  encoded = ENCODE_FILE (absname);
  char *fname = SSDATA (encoded);
  mode_t imode = XFIXNUM (mode) & 07777;
  if (emacs_fchmodat (AT_FDCWD, fname, imode, nofollow) != 0)
    report_file_error ("Doing chmod", absname);

  return Qnil;
}