The command ls . lists the contents of the current directory in Unix and Linux shells. It offers a quick way to confirm which files and folders exist where you are working.
This article explains how ls . behaves, why the dot matters, and what you can expect across different environments. It covers practical interpretation, environment-specific behavior, and common patterns.
| Command | Target | Effect | Visibility |
|---|---|---|---|
| ls . | Current directory | List names and details of entries in . | Hidden files shown only with -a |
| ls .. | Parent directory | List entries one level up | Hidden files shown only with -a |
| ls -l . | Current directory | Long format with permissions and timestamps | Hidden files shown only with -a |
| ls -a . | Current directory | Include entries starting with . | Shows dotfiles and dot-directories |
Behavior of ls Dot Current Directory
When you run ls ., the shell resolves the dot to the current working directory and asks ls to list it. The output is the same as ls without arguments in many setups, but explicitly using the dot keeps behavior predictable when the environment changes.
Using the dot anchors paths relative to where you are, which is helpful in scripts. If the current directory is removed or renamed during execution, ls . may fail, whereas ls without arguments relies on the shell to provide the current directory path differently.
Hidden Files and Dot Directories
By default, ls . does not show hidden files and folders whose names start with a dot. To include them, add the -a or -A flag, which reveals entries like .config or the parent link .. in a consistent way.
In scripts, using ls . instead of plain ls avoids ambiguity when the shell option nounset is enabled. It clearly states that the target is the current directory and not a missing variable or relative path.
Output Format and Sorting
ls . applies the default sorting and formatting rules of the ls implementation on your system. You can refine this with flags such as -l for long format, -t for time sorting, or --color=always for visual cues in terminals.
Different operating systems may add or omit columns such as block count or file labels. The core behavior of listing the current directory remains stable, but column widths and indicator characters depend on local settings and locale.
Environment and Platform Differences
On Linux, macOS, and BSD systems, ls . works consistently as long as you have read permission for the directory. BusyBox and other minimal environments may implement a reduced feature set, so check your specific toolchain when writing portable scripts.
Windows users running Git Bash, WSL, or similar layers can use ls . as long as the underlying core utilities are present. Native cmd and PowerShell use different commands, so the same dot-target logic does not apply directly there.
Best Practices with ls Dot
- Use ls . in scripts to clearly indicate the current directory as a target.
- Prefer ls -l . or ls -la . when you need detailed information.
- Combine flags like -t, -S, or --reverse to control sorting for readability.
- Test scripts in minimal environments such as containers or BusyBox to ensure compatibility.
- Check locale and alias settings that may alter color, size, or name formatting.
FAQ
Reader questions
Why does ls . sometimes show different results than ls without arguments?
ls . explicitly targets the current directory, while plain ls may rely on shell behavior, aliases, or default paths that can be influenced by the environment or options.
How can I include hidden files when using ls .?
Use ls -a . or ls -A . to include or differentiate hidden entries, depending on whether you want to see parent and current directory links.
What happens if the current directory is deleted while ls . is running?
The command may fail or show unexpected output because the directory inode is no longer accessible, even though the shell initially resolved the dot.
Does ls . work the same on all operating systems?
Linux and Unix-like systems generally behave consistently, while Windows native shells do not support this syntax unless through compatibility layers like WSL.