0
0
Linux CLIscripting~5 mins

ls (list files and directories) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to see what files and folders are in a place on your computer. The ls command shows you a list of these files and folders so you know what is there.
When you want to check what files are in your current folder before opening or editing them
When you need to find out if a file was saved in a specific directory
When you want to see hidden files that start with a dot in your folder
When you want to see detailed information like file size and modification date
When you want to list files sorted by time or size to find recent or large files
Commands
This command lists all visible files and folders in the current directory.
Terminal
ls
Expected OutputExpected
Documents Downloads example.txt Pictures Videos
This command lists all files including hidden ones that start with a dot.
Terminal
ls -a
Expected OutputExpected
. .. .bashrc Documents Downloads example.txt Pictures Videos
-a - Show all files including hidden ones
This command lists files with detailed information like permissions, owner, size, and modification date.
Terminal
ls -l
Expected OutputExpected
-rw-r--r-- 1 user user 1234 Apr 25 10:00 example.txt drwxr-xr-x 2 user user 4096 Apr 20 09:00 Documents drwxr-xr-x 3 user user 4096 Apr 22 15:30 Downloads
-l - Show detailed file information
This command lists files in long format sorted by modification time, newest first.
Terminal
ls -lt
Expected OutputExpected
-rw-r--r-- 1 user user 1234 Apr 25 10:00 example.txt drwxr-xr-x 3 user user 4096 Apr 22 15:30 Downloads drwxr-xr-x 2 user user 4096 Apr 20 09:00 Documents
-t - Sort files by modification time
-l - Show detailed file information
Key Concept

If you remember nothing else, remember: ls shows you what files and folders are in a directory, and flags like -a and -l help you see hidden files and details.

Common Mistakes
Running ls without knowing the current directory
You might look at the wrong folder and not find the files you expect
Use pwd to check your current directory before running ls
Expecting ls to show hidden files without -a flag
Hidden files starting with a dot won’t appear without -a
Add -a flag to see hidden files: ls -a
Using ls -l but not understanding the output columns
You might misinterpret file permissions, sizes, or dates
Learn the meaning of each column in ls -l output for correct understanding
Summary
ls lists files and folders in the current directory.
Use ls -a to include hidden files in the list.
Use ls -l to see detailed information about each file.