The ls
command is essential when navigating a file system. ls
displays files and directories in a given file system path. Yet, there’s a nuance when displaying files using the plain ls
command: it’s not listing dotfiles.
Dotfiles are the “hidden” files on your hard disk that start with a dot. Typically, a file explorer hides such files. A common dotfile is the .bashrc
file, or a directory example is the .git
folder in a git repository.
This tutorial shows you how to display all files and folders in a directory, including dotfiles.
Ubuntu/Debian Series Overview
- Fix “sudo command not found”
- Install a Specific Version with apt-get on Ubuntu/Debian
- Fix Ubuntu/Debian apt-get “KEYEXPIRED: The following signatures were invalid”
- How to Test a Cron Job
- How to Unzip Into a Folder
- How to Show Your Elasticsearch Version on Ubuntu/Debian
- Use “which” in Linux to find the Location of an Exetable
- Sort “ls” by Last Changed Date
- How to Shutdown a Machine
- Show Hidden Files and Folders with `ls`
Display All Files and Folders
Use ls -a
to display all files and folders in a file path. The -a
flag is an alias for the —all
flag and tells ls
not to hide dotfiles:
ls -a
# or with full flag name
ls --all
Example: Show All Files and Folders in Columns
Here’s an example showing all files and folders in a project directory. We’ve reduced the number of files and folders for a better overview. You can see that the ls -a
command displays dotfiles like .gitignore
and also hidden directories like .project
. Also, it shows the implicit .
and ..
paths:
$ ls -a
. .gitignore package.json
.. .project vite.config.ts
All Files and Folders as a List
Instead of printing them in columns, you can also list the files and folders. Append the -l
flag or combine them in a single flag to ls -al
. Notice, ls -la
is the same as ls -al
. You can change the order of flags as you want.
$ ls -al
.
..
.gitignore
package.json
.project
vite.config.ts
Display Almost All Files and Folders
The ls -a
flag displays the implicit .
and ..
paths. The ls
command offers the —almost-all
flag to hide these paths. You may also use the -A
alias instead of the full —almost-all
:
ls -A
# or with full flag name
ls --almost-all
Almost All Files and Folders in Columns
Displaying almost all files and folders in a given file path surfaces the dotfiles and hides the implicit .
and ..
paths.
$ ls -A
.gitignore package.json
.project vite.config.ts
Almost All Files and Folders as a List
You can also print the files and folders as a list. Append the -l
flag to print the listing in combination with almost all files and folders:
$ ls -Al
.gitignore
package.json
.project
vite.config.ts
That’s it!