/ linux / commands-deepdive

A deeper look at how Linux commands actually run and how the permission model controls what you can do on the system.

How a command is executed

When you type a command, the shell does three main things:

  1. Parse the command line – split into tokens, expand variables, handle quotes and globbing.
  2. Locate the executable – the shell searches the directories in PATH until it finds a file that is marked executable.
  3. Fork & exec – the shell forks a child process and the child replaces its image with the binary usingexecve().

The child process inherits the parent’s environment, but the shell can modify it (e.g., PATH, HOME) before exec. If the binary is a script, the kernel runs the interpreter specified by the shebang (e.g., #!/usr/bin/env bash).

File permissions & user identity

Every file has three permission triplets: user,group, and others. Each triplet can contain read (r), write (w), and execute (x) bits. These bits determine who can read, modify, or run the file.

rwxr-x--x

Owner can read/write/execute, group can read/execute, others only execute.

The owner is the user who created the file; thegroup is the primary group of that user. The kernel checks these bits before any process can open or run a file.

Managing permissions

  • chmod – change mode bits (e.g., chmod 755 file)
  • chown – change owner and/or group (e.g., chown alice:staff file)
  • chgrp – change only the group
  • umask – default permission mask for newly created files

Use ls -l to view the permission string and ownership.

Running commands as another user

Most administrative tasks require root privileges. The two most common ways to elevate are:

  1. sudo – runs a command with the permissions of another user (default root). It consults /etc/sudoers to decide who may run which commands.
  2. su – switches the current shell to another user’s environment. It requires the target user’s password unless you’re root.

Tip: Use sudo -l to list the commands you’re allowed to run.