Ubuntu: Create, Remove and manage folders
π Create and Delete a Folder (Directory) in Linux
β Create a Folder
To create a folder (directory), use:
sudo mkdir /path/to/foldername
- This creates a new directory at the specified path.
- Use the
-p
flag if parent directories donβt exist yet:
sudo mkdir -p /path/to/foldername
ποΈ Delete a Folder
To remove an empty directory:
sudo rmdir /path/to/foldername
If the folder is not empty, use:
sudo rm -r /path/to/foldername
β οΈ Be cautious with
rm -r
β it deletes everything inside the folder.
π Change Folder Permissions
1. Change Ownership (user and group):
sudo chown username:groupname /path/to/foldername
Example:
sudo chown john:john /path/to/foldername
2. Change Access Rights (Permissions):
sudo chmod 755 /path/to/foldername
Common permission modes:
755
β Owner can read/write/execute; others can read/execute.700
β Only the owner has full access.777
β Everyone has full access (not recommended for sensitive folders).
You can also use symbolic permissions:
sudo chmod u+rwx,g+rx,o+rx /path/to/foldername