What happens to old files?

QuestionsQuestions8 SkillsProDec, 24 2025
095

That is a very insightful question!

The short answer is: Nothing happens to them. They stay exactly as they were.

In Linux, file ownership is "static." When you create a file, the system writes the numerical ID of the user (UID) and the group (GID) onto that file's metadata on the disk.

If you change your primary group later, the file doesn't know and doesn't care. Here is the breakdown of what happens:

1. Ownership stays with the "Old" Group

If your primary group was labex (GID 5000) and you change it to developers (GID 6000):

  • Your old files still have GID 5000 stamped on them.
  • Your new files will now have GID 6000 stamped on them.

2. You might lose access to your own files!

This is the "gotcha" of changing primary groups. If a file has permissions like -rw-rw---- (Owner and Group can read/write, but Others cannot):

  • If you are no longer a member of the old group, and you are no longer the owner, you could effectively lock yourself out of that file.
  • Note: Usually, you are still the Owner (UID), so you can still get in, but the "group" benefits are gone.

3. How to fix the "Old Files"?

If you change your primary group and want all your old files to move to the new group with you, you have to do it manually using the chgrp (change group) command:

# Change group of a specific file
chgrp newgroup_name old_file.txt

# Or change everything in your folder recursively
chgrp -R newgroup_name /home/labex/project

Summary Table

Action What happens to Old Files? What happens to New Files?
Change Primary Group Remain assigned to the old GID. Assigned to the new GID.
Delete a Group Files become "orphans" (they show a number instead of a name). N/A

This is why system administrators are very careful when changing IDs—it can create a "mismatch" between the user's current identity and the identity stamped on their data!

0 Comments

no data
Be the first to share your comment!