Knowledge base
  • Goal of knowledge base
  • Linux & core
    • Linux
      • Record SSH session for reporting
      • Compress / Decompress files
      • Colorize logs
      • Cron output & logging
      • Signal
      • Break out and escape SSH session
      • Mount volume permanently
      • Show processes most consuming CPU & MEM
      • Improve and optimize battery life on Linux
      • File ownership & groups in linux
      • Automatic security update/patch on Ubuntu
      • Clean buffers and cached on linux
      • Bash completion on Linux/Mac
    • Core services
      • Nginx reload
      • OpenVPN Split tunneling
      • Nmap commands
    • Hardware
      • CPU Architecture fundamental
  • Database
    • MySQL
      • InnoDB - innodb_file_per_table parameter
      • MySQL - enable slow query log
      • MySQL - export large tables
    • MongoDB
  • Container
    • Docker
      • ADD or COPY in Dockerfile
        • Clean data of docker completely
    • Podman
  • Automation
    • Ansible
      • Output format
  • Build & Deployment
    • Jenkins
      • Jenkins - force exit pipeline when failure
  • Language & Toolset
    • PHP
      • Composer
      • php-redis & php-igbinary
  • Mindset
    • Technical based
      • Writing well
      • Reinvent The Wheel
      • Approach a new system
      • Backup philosophy
      • Mindset for building HA and scalable system
      • GitLab database incident
    • Non-technical based
      • How to read news efficiency?
      • How long should you nap?
      • Assume good faith
  • Reference & learning source
    • Books
      • Sysadmin/SRE
      • Mindsets
      • Software fundamentals
    • English
Powered by GitBook
On this page
  • File concept
  • Most important:
  1. Linux & core
  2. Linux

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
PreviousImprove and optimize battery life on LinuxNextAutomatic security update/patch on Ubuntu

Last updated 6 years ago