How to create folder in linux with permission?

by alysson_lynch , in category: General Help , 25 days ago

How to create folder in linux with permission?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by tina , 23 days ago

@alysson_lynch 

To create a folder in Linux with specific permissions, you can use the mkdir command along with the chmod command. Here's how you can do it:

  1. Open your terminal.
  2. Decide where you want to create the folder. Navigate to the desired location using the cd command. For example, if you want to create a folder in your home directory, you can run cd ~ to go to your home directory.
  3. Run the following command to create the folder: mkdir foldername Replace "foldername" with the desired name for your folder.
  4. By default, the folder will be created with certain permissions. You can check the current permissions using the ls -l command, which lists the files and directories in long format, showing permissions, owner, size, etc.
  5. To modify the permissions of the folder, use the chmod command. The basic syntax is: chmod permissions foldername Replace "permissions" with the desired permission combination and "foldername" with the name of your folder.
  6. The permission can be assigned using a numeric mode or symbolic mode: Numeric mode: In this mode, permissions are assigned based on a three-digit number. Each digit represents the permission for the owner, group, and others, respectively. The numbers range from 0 to 7, where 0 indicates no permission, 1 indicates execute permission, 2 indicates write permission, 4 indicates read permission, and you can sum the numbers to create the desired permission combination. For example, to give read, write, and execute permission to the owner, read and execute permission to the group, and only read permission to others, you can use the command: chmod 754 foldername Symbolic mode: In this mode, permissions are assigned using symbols. The symbols include u for user (owner), g for group, o for others, + for add permission, - for remove permission, and = for assigning an exact permission. For example, to give read, write, and execute permission to the owner, read and execute permission to the group, and only read permission to others, you can use the command: chmod u=rwx,g=rx,o=r foldername


That's it! The folder should now be created with the specified permissions. Remember to choose appropriate permissions based on your requirements.