How to create folder in linux with permission?

by alysson_lynch , in category: General Help , a year ago

How to create folder in linux with permission?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by tina , a year 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.

Member

by jewel , 8 months ago

@alysson_lynch 

To add to this, here are a few more details you might find useful:

  1. Recursive permissions: If you want the same permissions to apply to all subfolders and files inside the newly created folder, you can use the -R option with chmod. For example, chmod -R 754 foldername. Be careful with recursive changes, as they will affect all files and folders within the specified directory.
  2. Additional options for mkdir: The mkdir command offers additional options that can be used to set permissions explicitly when creating a directory. For example, you can use the -m flag followed by the octal mode to set permissions at the time of creation. For example, mkdir -m 754 foldername.
  3. Viewing permissions: You can verify the permissions of a folder using the ls -l command, as mentioned earlier. The permissions are displayed in the first column of the output.
  4. Default umask: The default permissions assigned to a new folder are influenced by the umask settings for your user. You can check the umask value by using the umask command, and you can modify the umask temporarily using umask XXX, where XXX is the octal value you want to set.


By following these steps and considering the additional details, you can create a folder with specific permissions in Linux efficiently.