Mastering Linux File Access: cat Commands, Users, Groups & Permissions


In the world of Linux, understanding how to view, manage, and protect your files is essential. While we've touched on a few basic cat
commands to view file content, there's much more to explore. In this blog, we’ll go deeper by introducing powerful commands like head
and tail
to control how data is displayed.
This blog continues your Linux learning journey by focusing on file permissions, user and group management, and how to secure your system effectively. You'll learn how to view file permissions, modify them using chmod
, and manage ownership using chown
and chgrp
. These are critical skills for maintaining a secure and organized Linux environment, whether you're a beginner or managing servers in production.
Let’s dive into the essential Linux commands and concepts that help you view file content with precision, manage user access, and secure your system using file permissions and ownership. From head
and tail
to chmod
, chown
, and chgrp
, this guide will walk you through practical examples every Linux user should know.
FYI : We can create a file directly using the vim command without needing to use the touch command first.
Example: vim myfile
Even if myfile does not already exist, this command will open a new file in Vim. When you save and exit (:wq), the file will be created.
When you open a file using the vim command, it will take you to command mode by default.
→ To start editing, switch to insert mode by pressing the i key. In insert mode, you can enter the content you want in the file.
JFYI - Note on Copy-Paste Behavior in Different Environments:
AWS Console (browser-based terminal):
→ Ctrl + C / Ctrl + V might not work as expected.
→ To paste: use Ctrl + Shift + V
→To copy: manually select the text, then right-click → Copy
Command Prompt / PuTTY (Windows):
→To copy: just select the text; it is copied automatically.
→To paste: simply right-click
Mac Users (Terminal):
To copy: C
To paste: V
→ After inserting your data in insert mode, press the Esc key to return to command mode.
→ Then, type :wq
and press Enter to save and exit the file.
CAT commands:
To view the contents of a file, use the cat
command: - cat filename
To view the contents of a file with line numbers, use the -n
option with the cat
command: cat -n filename
📄 Common Commands to View Specific Parts of a File in Linux:
→ Print the top 10 lines of a file: head filename ; top 3 lines: head -n 3 filename
(Here, -n
specifies the number of lines)
→ Print the bottom 10 lines of a file: tail filename ; bottom 3 lines: tail -n 3 filename
→ Print specific lines (e.g., lines 2 to 4): sed -n '2,4p' filename
→ Print a specific line (e.g., line 3): sed -n '3p' filename
🧮 Count Words, Lines, or Characters in a File:
→ To count the number of lines, words, and characters: wc filename
(wc = word count) ; o/p => 5 lines; 143 words ; 1039 characters; filename
→ To count only words: wc -w filename
→ To count only characters: wc -m filename (or) wc -c filename
→ To count only lines: wc -l filename
👤 User Commands in Linux: To View the List of All Users:
In most Linux systems, user information is stored in the /etc/passwd
file.
You can view all the users using either of the following commands:
getent passwd (or) cat /etc/passwd
✅ Explanation: cat is used to read and display the contents of a file.
Here, cat /etc/passwd reads the passwd file located in the etc folder.
Each line in this file represents a user on the system.
🎯 Why Do We Create Users?
Creating users allows you to manage access and permissions on a system.
For example: If someone wants to use your system only to watch movies, you can create a separate user account. You can give them restricted access, allowing them to access only the movie folder — not system files or other user data. Each user has their own username, password, and permissions.
🛡️ Real-Time Scenario (System Administration): A System Administrator (SysAdmin) creates a user account for each person who needs access to the server. They assign a username and password, along with specific permissions (like read, write, or execute) based on that user's role. This ensures security and controlled access to the server and its resources.
➕ To Add a User in Linux: To create a new user, use the useradd
command: useradd chandana
→ This creates a new user named chandana.
✅ To Verify if the User Was Added: Check the /etc/passwd file: cat /etc/passwd
Look for an entry like: chandana:x:1001:1001::/home/chandana:/bin/bash
Breakdown of the /etc/passwd Entry: (username : placeholder : UID : GID : comment : home directory : default shell)
In this case:
chandana → username
x → placeholder for encrypted password (actual password stored in /etc/shadow)
1001 → UID (User ID)
1001 → GID (Group ID)
(empty) → comment/description field (can include full name or other info)
/home/chandana → user's home directory
/bin/bash → default shell (Bash)
📌 NOTE: Whenever a new user is created, a group with the same name is also created by default. This is called a user private group, and its Group ID (GID) is usually the same as the user's UID.
To Check if a Specific User Exists: Use the id command followed by the username: id chandana
If the user exists, you will see output like:
uid=1001(chandana) gid=1001(chandana) groups=1001(chandana)
If the user does not exist, you will see an error message like: id: ‘chandana’: no such user
📂 Go to the /home
Directory and Check for the User Folder: cd /home/
ls or ll - This command navigates to the /home directory and lists its contents.
If a user named chandana was created properly, you should see a directory named chandana.
❌ To Delete a User and Their Home Directory: userdel -r chandana
userdel – deletes the user.
-r – stands for recursive: it removes the user's home directory and mail spool along with the user account.
→ userdel username (this will delete only user & group)
→ userdel -r username (this will delete all user, group & path also)
⚠️ Use this with caution, as it will permanently delete the user’s files and data from /home/chandana.
🔄 How to Switch to Another User (e.g., username) from Root: Use the su
command with the -
option: su - username
su stands for switch user. The - (hyphen) ensures that you load the login environment of the target user, including their environment variables and home directory. After running this command, you will be prompted to enter the password for username (unless you are root, who can switch without a password).
📌 Note: When you create files as one user, other users cannot see those files by default because each user has their own permissions and home directory. Files created in /home/username/ are owned by that user and are usually not accessible by other users unless permissions are explicitly changed.
This helps maintain privacy and security between different users on the system.
🔑 How to Set or Change Password for a User: passwd username
After running this, you will be prompted to enter the new password for that user.
Note: For security reasons, Linux does not show any characters (not even asterisks) while you type the password.
🔐 When Running as Root: If you are logged in as the root user, you won’t be asked for the current password to change the user’s password. Root has full privileges, so it can set or reset passwords directly.
👥 Groups in Linux: If you have 10 users and want to give them the same permissions, instead of assigning permissions individually, you create a group and add those users to it.
To List All Groups: getent group (or) cat /etc/group
📌 Important: When you create a new user, a group with the same name as the user is automatically created by default.
➕ To Create a New Group: Use the groupadd
command: groupadd groupname
Example: groupadd xyz - This creates a new group called xyz
.
To Check if a Group Has Been Added: You can view the list of groups by checking the /etc/group
file:
cat /etc/group
Here’s a step-by-step guide on how to add users and attach them to the group xyz
:
1. Create the group xyz
(if not already created): groupadd xyz
2. Add new users (e.g., user1, user2, user3):
useradd -m user1
useradd -m user2
useradd -m user3
The -m option creates a home directory for each user.
or you can use useradd user1 ……
3. Add each user to the group xyz
: usermod -aG groupname username
usermod -aG xyz user1
usermod -aG xyz user2
usermod -aG xyz user3-aG
means append the user to the supplementary group without removing them from other groups.
4. Verify users belong to group xyz
:
groups user1
groups user2
groups user3
Each should show xyz
listed among their groups.
(OR)
✅ Verify User’s Group Membership: To check the groups a user belongs to (for example, chandu
), use:
id chandu : The output will show the user ID (UID), primary group, and all supplementary groups the user is part of, including the group xyz
if the user was added correctly.
📌 Notes on Users and Groups:
You cannot add multiple users to a group in a single command.
You cannot create multiple users at the same time with one command.
You need to add or create users one by one.
To See How Many Users Are in a Group: getent group - This will list all groups along with their member users.
❌ To Delete a Group: Use the groupdel
command: groupdel groupname
Ex: groupdel XYZ
📄 Let’s Create a File: You can create a file using: touch myfile
After running: ls -l (or) ll
You might see output like: -rw-r--r--. 1 root root 0 Aug 14 20:26 myfile
Understanding the Output: -rw-r--r--. 1 root root 0 Aug 14 20:26 myfile
Breakdown:
- → Type of file (in this case, a regular file)
rw- → Owner (read & write permissions)
r-- → Group (read-only)
r-- → Others (read-only)
1 → Number of hard links
root → Owner name
root → Group name
0 → File size (in bytes)
Aug 14 20:26 → Last modified date and time
myfile → File name
📁 File Types in Linux (ls -l)first character):
- (hypen) - Regular file
d - Directory
c - Character device file
b - Block device file
🔐 File Permissions in Linux:
Example: rw-r--r-- : This string has 9 characters, broken down into three sets:
rw- Related to User (owner) permissions. (Read & write)
r-- Related to group permissions.(Read only)
r-- Related to others - processors(backend permissions). Read only (everyone else)
🧮 Permission Values (Numeric Representation):
Each permission is assigned a value:
r = 4 (read)
w = 2 (write)
x = 1 (execute)
- = 0 (no permission)
Permissions are added together to get a numeric value for each section:
rw- :Read + Write → 4 + 2 = 6
r-- :Read only → 4 + 0 = 4
r-- :Read only → 4 + 0 = 4
So, rw-r--r--
= 644
⚙️ Execute Permission (x): Needed to run or execute scripts and programs. Without x, even if you can read a script, you cannot run it.
🔢 Understanding Permission Values in Linux:
Linux file permissions are represented both symbolically (e.g., rwx
) and numerically (e.g., 7
).
✅ Example: Calculating Permission Values
User: rwx → 4 + 2 + 1 = 7
Group: --x → 0 + 0 + 1 = 1
Others: -w- → 0 + 2 + 0 = 2
So, permission value = 712
You can set this permission using: chmod 712 filename
🔓 Full Permissions: To give full permissions to everyone:
User: rwx = 4+2+1 = 7
Group : rwx = 4+2+1 = 7
Others : rwx = 4+2+1 = 7
Use: chmod 777 filename
This makes the file readable, writable, and executable by everyone — use with caution on servers!
💡 Why This Matters: When working on servers, you often need to adjust file permissions to control who can access or modify a file. Knowing these values helps you use chmod
efficiently.
🔧 To Change Permissions of a File: Use the chmod
command: chmod 777 filename
→ chmod stands for change mode.
→ 777 gives full permissions to user, group, and others.
⚠️ Note: Giving 777
is risky, especially on servers — anyone can read, write, and execute the file.
🔐 Default Permission: 644
When you create a file (like with touch
or vim
), it often has: -rw-r--r--
rw- :Read + Write → 4 + 2 = 6
r-- :Read only → 4 + 0 = 4
r-- :Read only → 4 + 0 = 4
So the numeric value is 644 (default for most regular files).
➕ To Add Extra Permissions to a File: Use the chmod +x
command to add execute (x
) permission:
chmod +x filename - This adds execute permission for user, group, and others.
🔄Example: Before: -rw-r--r--
User: rw- (read, write)
Group: r-- (read only)
Others: r-- (read only)
→After running chmod +x filename
-rwxr-xr-x
User: rwx (read, write, execute)
Group: r-x (read, execute)
Others: r-x (read, execute)
📝 Notes: +x adds execute permission. You can also target specific users:
chmod u+x filename → adds execute permission to the user only.
chmod g+x filename → adds execute to group.
chmod o+x filename → adds execute to others.
To Remove Extra Permissions to a File:
❌ chmod -x filename : This command removes execute (x
) permission from user, group, and others for the given file.
🔄 Example: Before: -rwxr-xr-x
User: rwx
Group: r-x
Others: r-x
After running: chmod -x filename
-rw-r--r-- : The execute permission is removed from everyone.
🎯 To remove execute permission selectively:
chmod u-x filename → removes execute from user
chmod g-x filename → removes execute from group
chmod o-x filename → removes execute from others
✅ Changing Permissions for Multiple Files at Once:
Yes, you can change permissions for multiple files in a single command using chmod
.
🔧 Syntax: chmod permission_value filename1 filename2 ...
Example: chmod 644 file1.txt file2.txt file3.txt
→This sets permission 644 (rw-r--r--) for all three files at once.
→ Useful when managing multiple files with the same required permissions.
▶️ Let’s Try It Step-by-Step:
Create sample files: touch aws swiggy zomato
Change permissions for all files: chmod 622 amazon swiggy zomato
Use ls -l (or) ll to verify the changes.
To Give Permissions to All Files in the Current Directory :chmod 644 * . This command sets permission 644 (rw-r--r--) for all files in the current directory.* is a wildcard that matches all files (but not hidden files starting with .). It does not affect subdirectories or files inside them.
⚠️ To Delete All Files in the Current Directory: rm -rf *
rm = remove
-r = recursive (removes directories and their contents)
-f = force (no confirmation)
* = all files and folders in the current directory
⚠️ Warning: This is a dangerous command. It will permanently delete everything in the current directory without asking for confirmation.
📁 Create a Folder and Add Files:
To create a folder: mkdir myfolder
go to the folder: cd myfolder/
create files inside the folder: touch aws swiggy prime zomato
→ This creates a folder called myfolder and four files inside it.
🔙 Go Back to Root (or Parent Directory): cd ..
⚠️ Set Permissions Only on the Folder (Not Files Inside): chmod 666 myfolder
→ This only changes permissions on the folder itself, not on the files inside it.
→ The folder will have rw-rw-rw- permissions, but the files inside will retain their original permissions.
✅ To Set Permissions on Folder and Everything Inside (Recursively):
chmod -R 666 myfolder (or) chmod permissionvalue foldername -R
Ex: chmod 666 myfolder -R
-R stands for recursive. This applies the permission to the folder and all its contents (files and subdirectories).
🎯 To Give Permissions Only to Files Inside a Folder: chmod 777 myfolder/*
→ This applies 777 (rwxrwxrwx) permissions to all files directly inside myfolder.
→ It does not change the permission of the myfolder directory itself or subdirectories (if any)
To View Permissions of Files Inside the Folder: ll (or) ll myfolder/ (or) ls -l myfolder/ - This will list all files inside myfolder
along with their permissions.
📝 Example File Details: -rw-r--r--. 1 root root 0 Aug 14 20:26 myfile
Let’s break it down: -rw-r--r--. → Default file permissions
1 → Link count - this means the number of hard links
root root → File ownership: (1st root = User (owner of the file) ; 2nd root = Group (group that owns the file))
🗒️ Note: The user who creates the file becomes its owner, and by default, the file is also assigned to a group with the same name (unless otherwise specified).
👤 How to Change the Owner (User) of a File: Use the chown
command: chown username filename
Example: chown chandana aws
→ This changes the owner of the file aws to the user chandana. chown stands for change owner.
👥 How to Change the Group Owner of a File: Use the chgrp
command: chgrp groupname filename
→ chgrp = change group. This command changes the group ownership of a file or directory.
✅ Example: chgrp chandana xyz
This changes the group owner of the file xyz to the group chandana.
→ To check the current user and group ownership, use: ls -l filename (or) ll
🔄 To Change Both User and Group Ownership of a File:
Use the chown
command with the following syntax: chown username:groupname filename
🔚 Conclusion:
Mastering file access in Linux goes far beyond just viewing file content — it’s about understanding how files are controlled, who can access them, and how to secure them effectively. With commands like cat
, head
, and tail
, you can quickly inspect data, while tools like chmod
, chown
, and chgrp
give you full control over permissions and ownership.
By learning how users and groups work in Linux, and how to manage them properly, you’re building a solid foundation for working confidently in any Linux environment — whether you're managing personal projects or administering production servers.
Keep practicing, and you’ll turn these essential commands into everyday tools. If you have questions or thoughts, feel free to leave a comment or share this with fellow tech enthusiasts! Thanks for reading🙏
😄Happy learning!
Subscribe to my newsletter
Read articles from Chandana Reddy directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Chandana Reddy
Chandana Reddy
Hi, I'm Chandana—a curious soul navigating the world through study, reflection, and shared wisdom. My journey is rooted in self-education: exploring new ideas, skills, and perspectives that empower personal growth. I believe that learning isn’t limited to classrooms—it’s an everyday practice that transforms who we are and how we connect. Through writing, conversations, and community-building, I share insights and tools that help others learn with purpose and passion. I’m not just a student of life—I’m a contributor to its knowledge ecosystem.