Ubuntu: Create, Remove and manage folders

Ubuntu: Create, Remove and manage folders

April 23, 2025 Linux Server System Administration Useful information 0

πŸ“ 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