</>
Skip to content
Bash lessons (23/29)

Bash — Directories

Directory operations

#!/bin/bash

mkdir -p dir/subdir    # Create directories
rmdir dir              # Remove empty directory
rm -rf dir             # Remove directory and contents
cp -r src dest         # Copy directory
mv src dest            # Move/rename directory

Navigation

#!/bin/bash

cd /path           # Change directory
cd ..              # Go up one level
cd ~               # Go to home
cd -               # Go to previous directory
pwd                # Print working directory

Listing

#!/bin/bash

ls                 # List files
ls -la             # List with details
ls -lh             # Human-readable sizes
ls -lt             # Sort by time
ls -lS             # Sort by size
tree               # Directory tree

Directory info

#!/bin/bash

du -sh *           # Directory sizes
du -sh dir         # Specific directory
df -h              # Disk space
find . -type d     # Find directories

Mini Practice

Write Bash code that:

  1. Creates a nested directory structure
  2. Lists directories with tree
  3. Checks disk usage with du
  4. Navigates with cd shortcuts

Up Next

In the next lesson, you'll learn about Permissions — file and directory permissions.

Related Topics

Frequently Asked Questions about Directories

What is Directories in Bash?

Directories is a fundamental concept in Bash. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Directories?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Directories.

Why is Directories important in Bash?

Directories is essential for Bash development. Understanding this concept will help you write better code and solve real-world problems more effectively.