Appearance
Working with Directories
Directories (or folders) form the backbone of your project organization. When working in Linux, WSL, or macOS, it’s essential to know how to create, rename, move, and manage directories efficiently using terminal commands. This becomes especially important for simulation workflows, where you’ll organize geometries, meshes, scripts, and results across multiple folders.
Understanding Directories
In Linux-based systems, everything — from files to devices — is organized inside a directory tree, starting from the root (/). Your workspace for simulations usually resides inside your home directory (~), or inside your mounted drive (e.g., /mnt/d/ in WSL).
Example path structure:
/mnt/d/fenics-projects/
├── beam/
│ ├── geometry/
│ ├── mesh/
│ ├── solver/
│ └── results/
└── logs/Having such a structured approach keeps your work organized and reproducible.
Creating Directories
To create new folders:
| Command | Description | Example |
|---|---|---|
mkdir folder_name | Creates a single new directory | mkdir simulations |
mkdir -p path/folder/subfolder | Creates nested directories (parent + child) | mkdir -p beam_project/mesh/outputs |
Tip: Use descriptive names like
mesh_files,solver_scripts, orresults_2025to make your directory structure self-explanatory.
Viewing Directory Contents
To see what’s inside a directory:
| Command | Description | Example |
|---|---|---|
ls | Lists all files and folders | ls |
ls -l | Displays details like permissions, size, and date | ls -l |
ls -a | Shows hidden files (those starting with a dot .) | ls -a |
ls -lh | Lists contents with human-readable sizes | ls -lh |
Navigating Between Directories
Move through directories with these basic commands:
| Command | Description | Example |
|---|---|---|
cd folder_name | Move into a directory | cd mesh |
cd .. | Move one level up | cd .. |
cd ../.. | Move two levels up | cd ../.. |
cd ~ | Jump back to your home directory | cd ~ |
cd \ | Jump to the root directory | cd \ |
cd /mnt/d/fenics-projects | Move directly to an absolute path | cd /mnt/d/fenics-projects |
Tip: Press Tab for auto-completion while typing directory names.
Renaming and Moving Directories
You can rename or relocate folders using the mv (move) command:
| Command | Description | Example |
|---|---|---|
mv old_name new_name | Rename a folder | mv test_mesh final_mesh |
mv folder1 /new/location/ | Move a folder to another location | mv mesh /mnt/d/archives/ |
Copying and Removing Directories
Sometimes, you may want to duplicate a directory or remove one completely.
| Command | Description | Example |
|---|---|---|
cp -r source destination | Copy a directory and its contents | cp -r mesh mesh_backup |
rm -r folder_name | Delete a folder and all files inside it | rm -r old_results |
rm -rf folder_name | Force delete without confirmation (use with caution) | rm -rf temp_files |
Always double-check before using
rm -rf, as it permanently deletes data without recovery.
Checking Your Current Location
You can always confirm your current directory path using:
pwdExample output:
/mnt/d/fenics-projects/beam/meshThis helps you keep track of where you are before executing file or folder operations.
Summary
Working confidently with directories allows you to stay organized and efficient — an essential habit for scientific computing and simulation work.
You’ve learned how to:
- Create, rename, move, and remove directories
- Navigate between different levels of your workspace
- Maintain clean and structured project folders
In the next section, we’ll explore file permissions and ownership, which determine who can access, modify, or execute files within your Linux environment.