|
|
|
Shell provides several commands for working with directories: mkdir, rmdir, ls, find, and more. |
|
|
Create a directory with mkdir: |
|
|
Create nested directories with -p: |
|
|
-p also doesn’t error if directory exists: |
|
|
Remove empty directory with rmdir: |
|
|
Remove nested empty directories: |
|
|
List directory contents with ls: |
|
|
Hidden files (start with .): |
|
|
Check if directory exists: |
|
|
Change directory with cd: |
|
|
Use subshell to avoid changing current directory: |
|
|
Find files in directory with find: |
|
|
Find with depth limit: |
|
|
Find with exec: |
|
|
Find files by age: |
|
|
Directory size with du: |
|
|
List subdirectory sizes: |
|
|
Count files in directory: |
|
|
Iterate over directory contents: |
|
|
Safe handling of special characters: |
|
|
Copy directory with cp -r: |
|
|
Move/rename directory: |
|
|
Remove directory and contents with rm -r: |
|
|
Temporary directory: |
|
|
Get home directory: |
|
|
Special directories: |
|
|
Bash
Directory stack (pushd/popd in bash): |
|
|
Check for empty directory: |
|
|
Create directory only if it doesn’t exist: |
|
|
Cleanup test directories |
|