Master Linux Shell Commands and Permissions: A Practical Guide
This article explains the fundamentals of Linux shells, how they interact with the kernel, and provides a detailed walkthrough of user and file permissions, including symbolic and octal representations, common commands like chmod, chown, chgrp, umask, and the sticky bit for directory security.
Understanding the Linux Shell
The Linux kernel cannot be accessed directly by users; instead, a shell (command interpreter) such as bash acts as an intermediary, translating user commands for the kernel and returning results. This is analogous to using a graphical interface on Windows to interact with the OS kernel.
Shells are a generic term for command‑line interpreters; bash is one specific implementation.
Linux User Types and Switching
Linux defines two user categories: superuser (root) , who can perform any operation, and regular users , who have limited privileges. The command prompt reflects the user type ( # for root, $ for regular users).
To switch users, use the su command: su [username] Examples:
Switch from root to a regular user: su user Switch to root (password prompt may be omitted): su or
su -File Permission Basics
Permissions determine whether a user or process can read ( r), write ( w), or execute ( x) a file or directory. Permissions are assigned to three classes:
Owner (u)
Group (g)
Others (o)
File types are indicated by the first character in ls -l output: d – directory - – regular file l – symbolic link b – block device p – FIFO/pipe c – character device s – socket
Symbolic Permission Representation
rwx → read, write, executeExamples: r-- – read‑only -wx – write and execute only --- – no permissions
Octal Permission Representation
r = 4, w = 2, x = 1Combine values for each class (owner, group, others). For instance, 755 means:
Owner: rwx (7)
Group: r-x (5)
Others: r-x (5)
Changing Permissions
The chmod command modifies file permissions:
# Numeric mode chmod 777 file.txt # rwx for everyone # Symbolic mode chmod u+x,g-w,o=r file.txt # add execute for owner, remove write for group, set read for othersCommon options: -R – apply changes recursively to directories
Only the file owner or root can change a file’s permissions.
Changing Ownership
Use chown to change the file owner and optionally the group:
sudo chown root file.c # change owner to root sudo chown user:group file.c # change owner and groupChanging Group
Use chgrp to modify the group association:
sudo chgrp developers project/Umask – Default Permission Mask
The umask value masks out permission bits when new files or directories are created. Default values are 0022 for root and 0002 for regular users.
umask 022 # results in default 755 for directories, 644 for filesDirectory Permissions and Sticky Bit
Directory access requires:
Read (r) – list contents
Write (w) – create or delete entries
Execute (x) – enter the directory
The sticky bit ( chmod +t) restricts deletion within a directory: only the file’s owner or root can delete a file, even if others have write permission on the directory.
chmod +t /tmp # enable sticky bit on /tmpTypical use: shared temporary directories where users may create files but cannot remove each other’s files.
Summary
Shells translate user commands for the kernel; bash is a common shell.
Linux distinguishes superuser and regular users; su switches contexts.
Permissions are expressed symbolically (rwx) and numerically (octal); they apply to owner, group, and others.
Use chmod, chown, chgrp, and umask to manage access.
Directory execute permission ( x) is required to cd into it; read permission ( r) allows listing; write permission ( w) allows creating or deleting entries.
The sticky bit ( +t) protects files in shared directories from being removed by non‑owners.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
