# Best Bash Command for Clean Directory Listing in Microsoft’s AI-For-Beginners

> Discover the best bash command for a clean directory listing in Microsoft's AI-For-Beginners repo. Clone efficiently, exclude unneeded files, and save disk space. Get the perfect git clone and sparse checkout setup now.

- Repository: [Microsoft/AI-For-Beginners](https://github.com/microsoft/AI-For-Beginners)
- Tags: how-to-guide
- Published: 2026-07-02

---

**Use `git clone --filter=blob:none --sparse` combined with `git sparse-checkout set --no-cone '/*' '!translations' '!translated_images'` to clone the repository while excluding translation packs and large generated images, resulting in a clean directory listing that saves disk space and reduces clutter.**

The **AI-For-Beginners** repository by Microsoft is a comprehensive 12-week curriculum that includes 50+ language translations and auto-generated image assets, which can quickly consume storage and clutter your working directory. When you need a **clean directory listing** without these optional bulk files, the standard `git clone` command is insufficient. Instead, the repository’s official documentation recommends a specific sparse checkout strategy that filters out the `translations/` and `translated_images/` directories at clone time.

## Why Standard Cloning Creates Directory Clutter

Cloning the full repository downloads every language pack and generated asset, even if you only need the English curriculum and core notebooks. The `translations/` directory contains parallel versions of all lessons in dozens of languages, while `translated_images/` stores machine-generated localized diagrams. These directories are unnecessary for most learners and make navigation slower when browsing the file tree.

## The Best Bash Command for Clean Directory Listing

The optimal approach uses Git’s **sparse checkout** feature with **blob filtering** to create a partial clone that excludes specific directories. This method is endorsed in the repository’s README under the "Clean directory listing" section.

### How Sparse Checkout Works

Sparse checkout tells Git to populate your working directory with only the files and folders you specify, while `--filter=blob:none` ensures that excluded file content is never downloaded from the remote. The `--no-cone` flag allows precise pattern matching to exclude directories by prefixing them with an exclamation mark.

### Step-by-Step Implementation

Execute these commands in your terminal to achieve a clean directory listing:

```bash

# Clone without downloading all blobs, enabling sparse checkout

git clone --filter=blob:none --sparse https://github.com/microsoft/AI-For-Beginners.git
cd AI-For-Beginners

# Configure sparse checkout to include root contents but exclude translations

git sparse-checkout set --no-cone '/*' '!translations' '!translated_images'

```

After running these commands, your directory will contain only the core curriculum files (`lessons/`, `examples/`, `etc/`) while omitting the bulk translation data. The repository remains fully functional—you can still fetch excluded files later if needed—but your local listing stays minimal and focused.

## Alternative Approaches

While sparse checkout is the recommended method for this repository, you have two other options depending on your constraints:

- **Full clone with manual deletion**: Run `git clone https://github.com/microsoft/AI-For-Beginners.git` then manually `rm -rf translations/ translated_images/`. This wastes bandwidth and time, and the deleted files still exist in Git history consuming space.
- **Shallow clone**: Use `git clone --depth 1` to download only the latest commit. This reduces history size but still downloads all directories in that snapshot, so it does not solve the clean directory listing problem for this specific repository structure.

## Verifying Your Clean Directory

Confirm the sparse checkout worked correctly by listing the top-level contents. You should see `lessons/`, `examples/`, [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml), and other core files, but **not** the `translations/` or `translated_images/` directories:

```bash
ls -la

```

If you need to add excluded directories back later, use:

```bash
git sparse-checkout add translations/

```

## Summary

- **Use sparse checkout** with `--filter=blob:none` to avoid downloading unnecessary translation files and generated images from the AI-For-Beginners repository.
- **Exclude specific directories** using the pattern `'/*' '!translations' '!translated_images'` with the `--no-cone` flag for precise control.
- **Save disk space** and reduce visual clutter while maintaining full Git functionality for the core curriculum files.
- **Restore excluded content** later if needed using `git sparse-checkout add` without recloning.

## Frequently Asked Questions

### What is the difference between sparse checkout and shallow clone?

A shallow clone (`--depth 1`) reduces commit history but downloads all files in the current snapshot, including translations. Sparse checkout filters which directories appear in your working tree regardless of history depth, making it the superior choice for achieving a clean directory listing when specific folders contain optional content.

### Can I still access the translations after using sparse checkout?

Yes. The files remain available on the remote. To temporarily access excluded directories, run `git sparse-checkout add translations/` or disable sparse checkout entirely with `git sparse-checkout disable`. This flexibility allows you to maintain a clean default view while retaining access to internationalization files when necessary.

### Does the sparse checkout command work with older Git versions?

The `--filter=blob:none` and `--sparse` flags require Git 2.25 or newer. If you encounter errors, upgrade Git to ensure support for partial clone and sparse checkout features. The `--no-cone` mode specifically requires Git 2.27 or later for proper pattern matching with negated paths.

### Will sparse checkout affect running the Jupyter notebooks?

No. The core curriculum files in `lessons/` and `examples/` are included in the sparse checkout pattern `'/*'`. Since the notebooks and their dependencies reside outside the excluded directories, you can run `jupyter lab` and execute all PyTorch and TensorFlow examples immediately after the clean clone and Conda environment setup.