my-ls-1
is a custom implementation of the Unix ls
command, written in Go.
It mimics the behavior of ls
with support for several commonly used flags and colorized output.
-
📥
main.go
- Parses command-line arguments and flags (
-l
,-a
, etc.) - Starts the directory listing process
- Parses command-line arguments and flags (
-
🚩
flags.go
- Contains the
lsFlags
struct - Handles custom flag parsing (e.g.,
-laR
)
- Contains the
-
📂
listing.go
- Reads directory entries
- Handles recursion for
-R
- Filters based on visibility (
-a
)
-
🔃
sort.go
- Sorts entries:
- Alphabetically (default)
- By modification time (
-t
) - Reversed (
-r
)
- Sorts entries:
-
🖨️
format.go
- Handles output display:
- Short (default)
- Long format (
-l
)
- Shows block totals and permissions
- Handles output display:
-
🧰
utils.go
- Helper functions for:
- User/group name lookup
- File mode formatting
- Time formatting
- Helper functions for:
-
🎨
colors.go
- Adds terminal colors to filenames:
- Blue = directories
- Green = executables
- Cyan = symbolic links
- Adds terminal colors to filenames:
File | Role & Responsibility |
---|---|
main.go |
Entry point, argument parsing |
flags.go |
Flag management and parsing |
listing.go |
Directory reading, recursive traversal |
sort.go |
Sorting by name, time, and reverse |
format.go |
Long/short format display, block calculation |
utils.go |
Permissions, user/group lookup, time formatter |
colors.go |
Color logic for terminal output |
- Supports the following flags:
-l
: Long listing format-R
: Recursive directory listing-a
: Show hidden files (dotfiles)-r
: Reverse sorting order-t
: Sort by modification time
- Colorized output:
- 🔵 Blue for directories
- 🟢 Green for executables
- 🔷 Cyan for symbolic links
- Handles symlinks, hidden files, and nested paths
- Modular file structure for easy understanding and maintenance
# Build the program
go build -o my-ls-1
# List current directory
./my-ls-1
# Use with flags
./my-ls-1 -l
./my-ls-1 -la
./my-ls-1 -lrt
./my-ls-1 -R testdir
./my-ls-1 -lR testdir///subdir//
You can combine flags just like in the original ls
.
ls
behavior:
On some systems, the ls
command is aliased to include extra options (e.g., --group-directories-first
, --color=auto
, etc.)
This may affect how the output looks or is ordered.
To compare results correctly, use the raw command \ls
(with a backslash) to bypass any alias.
Example:
\ls -l
./my-ls-1 -l
- Vicky Apostolou
- Kostas Apostolou
- Yana Kopylova
With persistence, teamwork, and 💙
This project is for educational use. Feel free to reuse ideas and structure for learning Go or Unix systems.