Linux CLI HowTo 6 ๐ง Directory Management How To
6 – Directory Management How-To
1. How to create a single directory:
- Use
mkdirfollowed by one directory name - Example:
mkdir myfolder - This creates a new directory in current location
- Verify creation with
ls -la
2. How to create multiple directories simultaneously:
- Use
mkdirwith multiple directory names separated by spaces - Example:
mkdir folder1 folder2 folder3 - All directories are created in the current working directory
- This is more efficient than creating one at a time
3. How to create multi-level directory structures:
- Use
mkdir -poption for parent directory creation - Example:
mkdir -p project/src/components - The
-pflag automatically creates all missing parent directories - If any parent already exists, it won’t cause an error
4. How to create directories with custom permissions:
- Use
mkdir -mfollowed by permission mode - Example:
mkdir -m 750 secure_folder - Permission format: 3 digits representing owner/group/others
- Common modes: 755 (read/write/execute for all), 750 (restricted access)
5. How to view directory information:
- Use
ls -lacommand to list all files and directories - Shows hidden files, permissions, ownership, and sizes
- Displays directory listing in long format with detailed information
6. How to delete empty directories:
- Use
rmdircommand followed by directory name - Example:
rmdir empty_folder - Only works on empty directories
- Directory must be empty before deletion
7. How to delete directories with contents:
- Use
rm -roption to remove recursively - Example:
rm -r folder_with_files - The
-rflag removes directory and all its contents - Be extremely careful as this operation cannot be undone
8. How to create a complete directory structure:
- Create parent directories:
mkdir -p main/sub1/sub2 - Create additional directories:
mkdir dir1 dir2 dir3 - Set specific permissions:
mkdir -m 750 secure_dir - Verify creation:
ls -la
9. How to safely delete directories:
- Check contents first:
ls -la directory_name - Remove empty directories with:
rmdir directory_name - For non-empty directories use:
rm -r directory_name - Always double-check before using
-roption
10. How to set up a typical project directory structure:
- Create main project folder:
mkdir project_name - Create subdirectories:
mkdir -p project_name/{src,docs,test,assets} - Set appropriate permissions for sensitive directories
- Verify structure with
ls -la project_name
11. How to avoid common mkdir errors:
- Check if directory already exists before creating
- Use
-pflag to prevent parent directory errors - Ensure proper permissions are set when needed
- Test with
echoorlsbefore final creation
12. How to create secure directories with restricted access:
- Use
mkdir -m 750for read/write/execute for owner only - Set group permissions appropriately
- Avoid using 777 permissions unless absolutely necessary
- Regularly check directory permissions with
ls -la
13. How to create multiple similar directories:
- Use pattern matching with wildcards if supported by shell
- Create a script that runs multiple
mkdircommands - Example:
mkdir -p project_{a,b,c}/src/{css,js,assets} - This creates 3 projects each with src subdirectories
14. How to maintain directory structures:
- Regularly remove unused directories with
rm -r - Use
findcommand to locate old or unnecessary directories - Keep track of directory creation dates for maintenance
- Always backup important directory structures before deletion
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!