Skip to content
Info Influx
Menu
  • Home
  • Oracle
  • Linux
  • SQL
  • Windows
  • Privacy Policy
  • About Us
  • Contact
Menu

Chmod & Chown command in Linux

Posted on July 31, 2023August 14, 2023 by siteadmin

Chmod command & Chown command are two essential commands in Linux used to manage file and directory permissions and change file ownership, respectively.

1. Chmod (Change Mode)

The chmod command is used to change the permissions (read, write, execute) of files and directories. It allows you to control who can access and modify them. File permissions are represented by a three-character string for the owner, group, and others. Each character indicates whether read (r), write (w), and execute (x) permissions are granted or not.

The syntax of the chmod command is as follows:

chmod [options] mode file(s)/directory(s)
  • mode: The permission mode you want to set using symbolic or numeric notation (explained in the previous answer).
  • file(s)/directory(s): The file(s) or directory(ies) for which you want to change the permissions.

Examples:

a) Grant read and write permissions to the owner of the file example.txt:

chmod u+rw example.txt

b) Set read, write, and execute permissions for all (user, group, and others) on a directory my_directory:

chmod a+rx my_directory

c) Remove write and execute permissions from the group and others for the script myscript.sh:

chmod go-wx myscript.sh

2. Chown (Change Owner)

The chown command is used to change the ownership of files and directories. It allows you to assign a new owner and group to one or multiple files and directories.

The syntax of the chown command is as follows:

chown [options] new_owner[:new_group] file(s)/directory(s)
  • new_owner: The new owner (either a username or a numeric user ID) to be assigned to the file or directory.
  • new_group: (Optional) The new group (either a group name or a numeric group ID) to be assigned to the file or directory. If not specified, the group will remain unchanged.
  • file(s)/directory(s): The file(s) or directory(ies) for which you want to change the ownership.

Examples:

a) Change the owner of the file example.txt to a user named john:

chown john example.txt

b) Change the owner and group of a directory my_directory to john and users, respectively:

chown john:users my_directory

c) Change the group of a file data.txt to a group with a numeric ID 1000:

chown :1000 data.txt

Both chmod and chown commands in linux are powerful tools for managing file and directory permissions and ownership on a Linux system. Always use them with caution and ensure you understand the implications of the changes you are making. Incorrect use of these commands can potentially lead to security risks or unwanted behavior in the system.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Multiplexing of Control Files
  • ORA-12012: error on auto execute of job SYS.ORA$AT_OS_OPT_SY_
  • Install Oracle 19c on Linux
  • Upgrade Oracle Database 12c to 19c (DBUA)
  • Install Oracle Database 12.2 on Linux

Archives

  • October 2023
  • August 2023
  • July 2023

Categories

  • Linux (7)
  • Oracle (25)
  • SQL (1)
  • Windows (3)
© 2026 Info Influx | Powered by Rama Solutions