ls

>Usage

The ls command (listing files) is utilized to display the files present in the current directory or a specified directory. Its various options provide additional information about the files and allow them to be sorted in different ways.

>Synopsis

ls [option] [directory-name]

>Options

-l

Shows the details of the file such as permissions, who created it, size, date of creation, file name.

Example: ls -l

Dots

> ls -l ~


drwx------+ 36 lpr staff 1152 Oct 31 20:33 Desktop
drwx------+ 4 lpr staff 128 Oct 15 13:33 Documents
drwx------+ 67 lpr staff 2144 Oct 31 20:31 Downloads
drwx------@ 82 lpr staff 2624 Oct 14 14:11 Library
drwx------ 4 lpr staff 128 Sep 15 19:25 Movies
drwx------+ 3 lpr staff 96 Sep 13 19:28 Music
drwx------+ 4 lpr staff 128 Sep 13 19:28 Pictures
drwxr-xr-x+ 4 lpr staff 128 Sep 13 19:28 Public

-a

Lists all files, including the hidden ones which will have . in front of them.

-d

Lists all the directories.

-h

Lists the file size in human-readable format (e.g., 2K, 5G, etc.)

Example:

Dots

> ls -lh ~


total 4
drwxr-xr-x@ 5 user staff 160B Nov 7 15:54 Applications
drwx------@ 8 user staff 256B Nov 19 22:21 Desktop
drwx------+ 16 user staff 512B Nov 19 11:13 Documents
drwx------@ 159 user staff 5.0K Nov 19 18:28 Downloads

-S

Lists all the files and directories, sorted by file size.

-t

Lists all the files and directories, sorted by time and date of creation.

>Quiz

Progress: Question ? out of ?

Question Title

Page written by Andrea Lepori