Interview Q&A / Linux & Shell

INTERVIEW Q&A · 63 QUESTIONS

Linux & Shell interview questions

Permissions, processes, pipes and the commands you are expected to know cold.

  1. How do file permissions work in Linux, and what do chmod 755 and 644 mean?

    Every file has read, write and execute permissions for three groups of people - the owner, the group and everyone else. chmod changes them; 755 means the owner can do everything while others can only read and execute, and 644 means the owner can read and write while others can only read.

    BeginnerIn-depth3 min read
  2. How do you change a file's owner and group with chown?

    Use chown user file to change the owner and chown user:group file to change both. Add -R to apply it to a whole directory tree. Only root can give files away to another user; chgrp changes just the group.

    BeginnerQuick answer1 min read
  3. What is the difference between symbolic and octal modes in chmod?

    Octal mode sets all permissions at once with numbers such as 640. Symbolic mode edits specific bits with letters, such as u+x or go-w, leaving the rest unchanged. Symbolic is safer for small tweaks; octal is better for setting a known final state.

    BeginnerQuick answer1 min read
  4. What does SGID do on a directory, and when is it useful?

    On a directory, SGID makes new files and sub-folders inherit the directory's group instead of the creator's primary group. It is used for shared team folders so everyone's files stay accessible to the same group. It shows as s in the group execute slot.

    IntermediateQuick answer1 min read
  5. What does the execute permission mean on a directory?

    On a directory, execute (x) means permission to enter it and access items by name. Read (r) lets you list names, and write (w) lets you create or delete entries. Without x on a directory you cannot cd into it or open files inside, even if the files themselves are readable.

    IntermediateQuick answer1 min read
  6. What is the sticky bit, and why does /tmp have it?

    The sticky bit on a directory means only a file's owner, the directory's owner or root may delete or rename files inside, even if others have write permission on the directory. It shows as a t at the end of the permissions, for example drwxrwxrwt.

    IntermediateQuick answer1 min read
  7. What is the SUID bit, and how can passwd change root-owned files?

    SUID makes an executable run with the permissions of its file owner instead of the user who launched it. passwd is owned by root with SUID set, so a normal user can update /etc/shadow through it. The bit shows as s in the owner execute slot.

    IntermediateQuick answer1 min read
  8. What is umask, and how does it decide default file permissions?

    umask is a mask of permission bits that are removed from the defaults for newly created files and directories. Files start from 666 and directories from 777, so a umask of 022 gives files 644 and directories 755.

    IntermediateQuick answer1 min read