ls's Examples

List directory contents. The ls command is used to list out files and directories. Some versions may support color-coding. The names in blue represent the names of directories.

ls -l filename

The ls command displays detailed information about files and directories found in the file system. It's part of the GNU core utilities package, which comes standard with every Linux distribution.

ls

How to list Files in a Directory with Options

ls [flags] [directory]

List files in the current working directory

ls

List files in another directory

ls [directory path here]

List files in the root directory

ls /

List files in the parent directory

ls ..
ls ../..

List files in the user's home directory (/home/user)

ls ~

List only directories

ls -d */

List files with subdirectories

ls *

List files recursively

ls -R

List files with their sizes

ls -s

List files in long format

ls -l

List files in long format with readable file sizes

ls -lh

List files including hidden files

ls -a

List files in long format including hidden files

ls -l -a
ls -a -l
ls -la
ls -al

List files and sort by date and time

ls -t

List files and sort by file size

ls -S 
ls -Sr
-r

List files and output the result to a file

ls > output.txt

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us