How to use chown to check the current file ownership

March 20, 2024 / How-to Guide

Chown command is primarily used to change file ownership, it does not offer a direct way to check the current ownership. However, you can effectively achieve this using the ls command with the -l (long listing) option.

This guide will walk you through the process of using chown to check the current file ownership.

Here is how it works –

  1. Open a terminal window.
  2. Navigate to the directory containing the file you want to check. Use the cd command for this purpose. For example-
    cd /path/to/directory.
  3. Execute the following command-
    ls -l filename
    Replace filename with the actual name of the file you want to examine.
  4. Interpret the output-
    The ls -l command displays various information about the file, including its permissions, owner, group, size, and last modification date. The first set of characters (usually ten characters long) represents the file permissions. Focus on the first three characters-
    The first character-
    – indicates a regular file
    d indicates a directory.
    Other characters represent special file types.
    The second and third characters represent the owner’s permissions-
    r : Read permission
    w : Write permission
    x : Execute permission
    – : No permission
  5. For example –
    -rw-r–r– 1 user group 1024 Mar 6  2024 filename
    In this example-
    The file is a regular file (-).
    The owner (user) has read (r), write (w), and execute (x) permissions.
    The group (group) and others have only read (r) permission.
    Therefore, the owner of the file is the user named “user”.

Additional Notes –

  1. If you need more detailed info about who owns a file and its permissions, you can also use commands like stat or getfacl. However, for a quick check, ls -l is simple and handy.
  2. Keep in mind, to change who owns a file using chown; you need to have the right permissions.

This was the end of our article. Hope you liked our KB and that you have understood everything well. If you need further assistance, get in touch with our support team.

Dominos Search