Master Linux chattr and chgrp: Control File Attributes and Groups
This guide explains the Linux chattr and chgrp commands, detailing their syntax, available options, and practical examples for modifying file attributes and group ownership, including how to set immutable, append‑only, and other flags, as well as recursive operations and version handling.
Linux chattr command
The chattr command is used to change file attributes on ext2/3/4 file systems.
It supports eight attribute flags:
a – allow only append operations.
b – do not update the file's last access time.
c – compress the file.
d – exclude the file from dump operations.
i – make the file immutable (cannot be modified or deleted).
s – secure deletion.
S – synchronous updates.
u – undelete flag.
Syntax
chattr [-RV] [-v<version>] [+|-=<attributes>] file_or_directory...Parameters
-R : Recursively apply to directories.
-v<version> : Set a version number for the file or directory.
-V : Show the command execution process.
+<attr> : Add the specified attribute.
-<attr> : Remove the specified attribute.
=<attr> : Set the attribute to a specific value.
Examples
Make a critical file immutable: chattr +i /etc/resolv.conf Verify the attribute: lsattr /etc/resolv.conf Output shows the i flag set.
Make a log file append‑only:
chattr +a /var/log/messagesLinux chgrp command
The chgrp command changes the group ownership of files or directories.
Syntax
Parameter description
-c or --changes : Report only the changes made.
-f or --quiet or --silent : Suppress error messages.
-h or --no-dereference : Affect only symbolic links.
-R or --recursive : Process directories recursively.
-v or --verbose : Show detailed operation output.
--help : Show online help.
--reference=<file> : Use the group of the reference file.
--version : Display version information.
Examples
Change the group of a file: chgrp -v bin log2012.log Output:
Explanation: The group of log2012.log is changed to bin.
Change group based on a reference file: chgrp --reference=log2012.log log2013.log Output:
Explanation: The group of log2013.log is set to match that of log2012.log.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
