> For the complete documentation index, see [llms.txt](https://knowledge.tracelog.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledge.tracelog.in/linux-and-core/linux/file-ownership-and-groups-in-linux.md).

# File ownership & groups in linux

### File concept

Every file in Linux is managed by a specific user and a specific group.

#### **1. Display ownership and group information:**

```
$ ls -l file.txt
-rw-rw-r-- 1 root www-data 0 Feb 25 15:51 file.txt
```

This file is owned by the root user and belongs to the www-data group.

#### **2. Change the ownership of a file by using chown**

**Important:** ONLY root user or members of the `sudo group` may transfer ownership of a file

```
$ sudo chown robert file.txt
$ ls -l file.txt
-rw-rw-r-- 1 robert www-data 0 Feb 25 15:51 file.txt
```

**3. Changing the Group Ownership of a file by using chgrp**

All users on the system belong to at least one group. You can find out which groups you belong to using the following command: `groups username`

Change the group ownership of a specific file using the chgrp command

```
$ chgrp webdev file.txt
$ ls -l file.txt
-rw-rw-r-- 1 robert webdev 0 Feb 25 15:51 file.txt
```

The file file.txt now belongs to the `webdev` group.

### Most important:

Change both the **owner** and **group** of a file using just the `chown` command

```
$ sudo chown tito:editors file.txt
$ ls -l file.txt
-rw-rw-r-- 1 tito editors 0 Feb 25 15:51 file.txt
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledge.tracelog.in/linux-and-core/linux/file-ownership-and-groups-in-linux.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
