Directory Operations
Basic Directory Management Commands
graph TD
A[Directory Operations] --> B[Create]
A --> C[Remove]
A --> D[Copy]
A --> E[Move/Rename]
Creating Directories
## Create a single directory
mkdir new_folder
## Create multiple directories
mkdir folder1 folder2 folder3
## Create nested directories
mkdir -p parent/child/grandchild
Removing Directories
## Remove an empty directory
rmdir empty_folder
## Remove directory with contents
rm -r full_folder
## Remove directory forcefully
rm -rf unwanted_directory
Advanced Directory Operations
Copying Directories
## Copy directory
cp -r source_directory destination_directory
## Copy with preservation of attributes
cp -rp source_directory destination_directory
Moving and Renaming
## Move directory
mv source_directory destination_directory
## Rename directory
mv old_name new_name
Directory Permissions and Ownership
Permission |
Symbolic |
Numeric |
Read |
r |
4 |
Write |
w |
2 |
Execute |
x |
1 |
## Change directory permissions
chmod 755 directory_name
## Change directory ownership
chown user:group directory_name
Recursive Operations
## Recursive copy with details
cp -rv source_dir destination_dir
## Recursive permission change
chmod -R 755 directory_name
Directory Comparison
## Compare directory contents
diff -r directory1 directory2
LabEx Tip
LabEx provides hands-on environments where you can practice these directory operations safely and interactively, helping you build confidence in Linux file system management.
Best Practices
- Always use
-i
flag for interactive confirmation
- Be cautious with recursive and force operations
- Double-check paths before executing commands
- Use tab completion to minimize typing errors