Skip to content

chentaymane/my-ls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

my-ls

A reimplementation of the Unix ls command written in Go.

Usage

./my-ls [flags] [file|directory ...]

If no path is given, the current directory is listed.

Flags

Flag Long form Description
-l Long format: permissions, links, owner, group, size, date, name
-a --all Include hidden entries (. and ..)
-R --recursive List subdirectories recursively
-r --reverse Reverse the sort order
-t Sort by modification time, newest first

Flags can be combined in any order: -la, -lRt, -laRrt, etc.

Examples

./my-ls                        # list current directory
./my-ls -l                     # long format
./my-ls -la                    # long format, include hidden files
./my-ls -lR /etc               # long format, recursive
./my-ls -lt /var/log           # long format, sorted by time
./my-ls -lRr /home             # long format, recursive, reversed
./my-ls -la /dev               # list /dev with device files
./my-ls file1 dir1 dir2        # mix of files and directories

Build

go build -o my-ls .

Requires Go 1.21+ on Linux.

Allowed packages

fmt · os · os/user · strconv · strings · syscall · time · errors · io/fs

os/exec is not used anywhere in this project.

Output

  • Default: multi-column layout sized to terminal width
  • -l: one entry per line with permissions, hard links, owner, group, size, modification time, and name
  • Device files (/dev): size field shows major, minor instead of byte count
  • Colors match the default GNU ls LS_COLORS:
    • Bold blue — directories
    • Bold cyan — symbolic links
    • Bold green — executable files
    • Bold yellow on black — block/character devices
    • Yellow on black — FIFOs / named pipes
    • Bold magenta — sockets
    • White on red — setuid files
    • Black on yellow — setgid files
    • White on blue — sticky directories
    • Blue on green — other-writable directories
    • Black on green — sticky + other-writable directories
    • Bold red on black — broken symbolic links

About

A ground-up re-implementation of the Unix ls command in Go. Supports -l, -R, -a, -r, and -t flags in any combination, with long format output identical to the native system command. Uses syscall for file metadata and os/user for ownership resolution. os/exec is strictly prohibited.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages