Site icon LinuxCommands.site

ls command tutorial in linux/unix with examples and use cases

linux ls command – list directory contents

Linux ls command is the most commonly used command in our daily use of linux. ls can not only display the name of each file and directory and its associated information, but also display a sorted list of files and directories according to the default or specified rules.

Syntax

 ls [OPTION]... [FILE]...

Options

Examples & Use Cases

List files and directories in the current directory

In the following example we will list all the contents of the directory, including hidden files and directories.

 ➜   ls -al

List files and directories sorted by time

In the following example we will list all the contents of the directory in reverse order of modification time.

 ➜  ls -lrt

List only directories

In the following example, we will list only the directories in the current directory.

 ➜  ls -dl */

Return only directory names and file names

In the following example, we will return only the directory name and file name in the current directory.

 ➜  ls -1

Exit mobile version