ls — List Directory Contents
ls shows you what's in a directory.
Basic usage
ls
Shows files in the current directory.
Common flags
ls -l # Long format (permissions, size, date)
ls -a # Show hidden files (starting with .)
ls -la # Both combined
ls -lh # Human-readable file sizes (KB, MB)
ls -lt # Sort by modification time
ls -lr # Reverse order
ls -R # Recursive (show subdirectories)
List a specific directory
ls /etc
ls /var/log
ls ~/documents
Understanding ls -la output
-rw-r--r-- 1 student student 42 Jan 15 10:30 hello.txt
drwxr-xr-x 2 student student 4096 Jan 15 10:00 documents
- First character:
-= file,d= directory,l= symlink - Next 9 characters: permissions (rwxrwxrwx)
- Number: hard link count
- Owner, group
- File size in bytes
- Date modified
- Filename