Syntax
Description
Thels command lists files and directories within Nash’s virtual filesystem. Without arguments, it lists the contents of the current working directory. It supports common flags for showing hidden files and detailed information.
Options
Show hidden files (files starting with
.)Use long listing format (show permissions, size, and name)
Combine flags: long format with hidden files
Parameters
One or more directories or files to list. If omitted, lists current directory. Supports multiple paths.
Behavior
- Default mode: Lists visible files in current directory, one per line
- Directories: Appended with
/in short format - Hidden files: Files starting with
.are hidden unless-ais used - Long format: Shows permissions, size, and name
- Multiple paths: Lists each path with headers
- Flag combining: Flags can be combined (e.g.,
-la,-al)
Examples
List current directory
List with hidden files
Long format listing
Long format with hidden files
List specific directory
List multiple directories
List a single file
Output Format
Short Format (default)
- Directories shown with trailing
/ - One entry per line
- No size or permission information
Long Format (-l)
- Column 1: Permissions (
dfor directory,-for file) - Column 2: Size in bytes (right-aligned, only for files)
- Column 3: Filename
Error Handling
Directory doesn’t exist
1
Permission denied (read-only mount)
If a directory cannot be read,ls will return an appropriate error from the VFS layer.
Implementation Details
- Source:
src/builtins/ls.rs - Uses
vfs.list_dir()to enumerate directory entries - Checks
vfs.is_dir()to determine entry types - Reads file size using
vfs.read()for long format - Filters entries starting with
.unless-ais specified - Supports flag combining (e.g.,
-laparsed as-l+-a)
File sizes are displayed in bytes only. There’s no
-h (human-readable) flag for KB/MB/GB formatting.Differences from Unix ls
| Feature | Unix ls | Nash ls |
|---|---|---|
| List files | ✅ Supported | ✅ Supported |
-a (all/hidden) | ✅ Supported | ✅ Supported |
-l (long format) | ✅ Supported | ✅ Supported |
-h (human-readable) | ✅ Supported | ❌ Not supported |
-R (recursive) | ✅ Supported | ❌ Not supported |
-t (sort by time) | ✅ Supported | ❌ Not supported |
-S (sort by size) | ✅ Supported | ❌ Not supported |
-r (reverse) | ✅ Supported | ❌ Not supported |
| Colors | ✅ Optional | ❌ No colors |
| Timestamps | ✅ Shown | ❌ Not tracked |
| Sorting | Multiple options | Unsorted |
