Skip to content

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:

CommandDescriptionExample
mkdir folder_nameCreates a single new directorymkdir simulations
mkdir -p path/folder/subfolderCreates nested directories (parent + child)mkdir -p beam_project/mesh/outputs

Tip: Use descriptive names like mesh_files, solver_scripts, or results_2025 to make your directory structure self-explanatory.

Viewing Directory Contents

To see what’s inside a directory:

CommandDescriptionExample
lsLists all files and foldersls
ls -lDisplays details like permissions, size, and datels -l
ls -aShows hidden files (those starting with a dot .)ls -a
ls -lhLists contents with human-readable sizesls -lh

Move through directories with these basic commands:

CommandDescriptionExample
cd folder_nameMove into a directorycd mesh
cd ..Move one level upcd ..
cd ../..Move two levels upcd ../..
cd ~Jump back to your home directorycd ~
cd \Jump to the root directorycd \
cd /mnt/d/fenics-projectsMove directly to an absolute pathcd /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:

CommandDescriptionExample
mv old_name new_nameRename a foldermv test_mesh final_mesh
mv folder1 /new/location/Move a folder to another locationmv mesh /mnt/d/archives/

Copying and Removing Directories

Sometimes, you may want to duplicate a directory or remove one completely.

CommandDescriptionExample
cp -r source destinationCopy a directory and its contentscp -r mesh mesh_backup
rm -r folder_nameDelete a folder and all files inside itrm -r old_results
rm -rf folder_nameForce 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:

pwd

Example output:

/mnt/d/fenics-projects/beam/mesh

This 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.