A lightweight bash wrapper for tree that provides sensible defaults for quick directory visualization.
lsd displays directory trees with a focus on simplicity: directories only, one level deep, directories first. It eliminates the need to remember tree flags for common operations.
Install with a single command:
curl -sSL https://raw.githubusercontent.com/Open-Technology-Foundation/lsd/main/install.sh | sudo bashOr using wget:
wget -qO- https://raw.githubusercontent.com/Open-Technology-Foundation/lsd/main/install.sh | sudo bashThis will install lsd, its manpage, and bash completion to /usr/local.
- Directories-only view by default (use
-ato include files) - Single-level depth by default (configurable with
-1through-9or-m) - Directories listed before files
- Optional detailed file listing with
--lsflag - Can pass through options directly to
treecommand - Dual-mode design: works as standalone script or sourced function
- Proper error handling with validation
- BASH-CODING-STANDARD compliant
Requirements: tree command must be installed
Optional (Recommended): dircolors for enhanced colorization
treeuses theLS_COLORSenvironment variable for file type colors- Configure via
~/.dircolorsor use projects like trapd00r/LS_COLORS - Without dircolors configuration,
treeuses built-in default colors
Use the provided Makefile to install all components:
# Install to /usr/local (default)
sudo make install
# Install to /usr
sudo make PREFIX=/usr install
# Check dependencies first
make check
# See all available options
make helpThis installs:
- Script to
/usr/local/bin/lsd - Manpage to
/usr/local/share/man/man1/lsd.1 - Bash completion to
/usr/local/share/bash-completion/completions/lsd
To uninstall:
sudo make uninstall# Make executable
chmod +x lsd
# Option 1: Copy to PATH
sudo cp lsd /usr/local/bin/
# Option 2: Source in your shell
source lsd # Exports lsd() function
# Option 3: Add to shell config for persistent use
echo 'source lsd' >> ~/.bashrc # If lsd is in PATH
# Or: echo 'source /path/to/lsd' >> ~/.bashrc # For custom location
# Install manpage (optional)
sudo cp lsd.1 /usr/local/share/man/man1/
sudo mandb
# Install bash completion (optional)
sudo cp lsd.bash_completion /usr/local/share/bash-completion/completions/lsdlsd [OPTIONS] [PATH...] [--|--tree TREE_OPTIONS]lsd # Current directory, directories only, 1 level
lsd -a # Include files in addition to directories
lsd -A # All files with detailed listing (combines -a --ls)
lsd /var /tmp # Multiple paths
lsd -3 /home # 3 levels deep
lsd -L 5 /usr # 5 levels deep (same as -m 5)
lsd -a --ls /etc # Files + directories with detailed listing| Option | Description |
|---|---|
-a, --all |
Show files and directories (default: directories only) |
-A |
Same as -a --ls; full listing for all files and directories |
-m, --maxdepth, -L, -l, --level N |
Traverse N levels (default: 1) |
-1 through -9 |
Shortcut for depth (e.g., -3 = 3 levels) |
--ls |
Show detailed file listing (permissions, size, date) |
-n, --nocolor |
Disable color output |
-C, --color |
Enable color output |
--, --tree |
Pass remaining arguments directly to tree |
-V, --version |
Show version |
-h, --help |
Show help |
# Files and directories, 2 levels, detailed listing
lsd -a -2 --ls ~/projects
# Quick full listing with -A option
lsd -A -3 /etc # Same as: lsd -a -3 --ls /etc
# Pass custom tree options
lsd -- -L 5 -a -I 'node_modules|.git'
# Multiple directories with custom depth
lsd -4 /usr/local /opt
# Aggregate short options
lsd -a3 /home # Equivalent to: lsd -a -3 /home
lsd -AC2 ~ # All files, color, 2 levels, detailed listing
# Directories only (default), no color
lsd -n /var/log
# All maxdepth aliases work the same
lsd -L 3 /home # Same as -m 3, -l 3, or --level 3Enable tab completion for lsd options and directories:
source lsd.bash_completionOr install system-wide:
sudo cp lsd.bash_completion /etc/bash_completion.d/lsdA comprehensive Unix manual page is available in lsd.1.
View without installing:
man ./lsd.1Install system-wide:
sudo cp lsd.1 /usr/local/man/man1/
sudo mandb # Update man databaseAccess after installation:
man lsdThe manpage includes detailed descriptions of all options, examples, installation instructions, and technical notes about dual-mode functionality.
lsd invokes tree with:
-d- Directories only (unless-a|--allspecified)-L 1- Maximum depth 1 level--dirsfirst- List directories before files
With --ls flag, adds:
-pugsD- Permissions, user, group, size, date--timefmt=%y-%m-%dT%R- ISO-style timestamp
Standalone executable: Run directly from PATH or local directory
lsd -3 /var
/usr/local/bin/lsd -a --ls /homeSourced function: Use in shell sessions or scripts
source lsd
lsd -2 ~/projectsThe script automatically detects execution mode using ${BASH_SOURCE[0]} and adapts accordingly.
The script validates:
treecommand availability (exit 127 if not found)- Numeric level arguments (exit 22 for invalid values)
- Proper error messages to stderr
tree- Directory listing program- Bash 4.0 or later
See project repository for license information.
#fin