Skip to content

MacOS ls command

The MacOS ls command is a powerful tool for listing directory contents. It allows users to view files and directories within a specified location. By using different options, users can customize the output to suit their needs. With ls, users can display timestamps, file sizes, permissions, and more. This command is essential for efficiently navigating and managing files on a MacOS system. Familiarize yourself with the different options available to maximize your productivity with the ls command.

ls Syntax:

Terminal window
ls [option] [parameter]

Options:

OptionDescription
-lUse a long listing format
-aInclude directory entries whose names begin with a dot (.)
-hWhen used with -l, shows file sizes in human-readable format
-tSort files by modification time
-rReverse the order of output
-RList subdirectories recursively

Parameters:

ParameterDescription
pathnameSpecifies the directory to list

ls Usage:

List all files and directories in the current directory

Terminal window
ls

This command lists all files and directories in the current working directory.

List all files and directories including hidden files

Terminal window
ls -a

This command lists all files and directories, including hidden files that start with a ”.”

Display file and directory permissions and ownership information

Terminal window
ls -l

This command displays a long listing format, showing file and directory permissions, ownership, size, and modification date.

List files and directories sorted by modification time

Terminal window
ls -t

This command lists files and directories sorted by modification time, with the most recently modified files shown first.

How do I list all files, including hidden files, in MacOS?

To list all files, including hidden files, in MacOS using the ls command, execute the following command:

Terminal window
ls -a

How do I show file details, including permissions, size, and modification date, in MacOS?

To show file details, including permissions, size, and modification date, in MacOS using the ls command, execute the following command:

Terminal window
ls -l

How do I list files in reverse order in MacOS?

To list files in reverse order in MacOS using the ls command, execute the following command:

Terminal window
ls -r

How do I display file sizes in human-readable format in MacOS?

To display file sizes in human-readable format in MacOS using the ls command, execute the following command:

Terminal window
ls -lh

How do I list files sorted by modification time in MacOS?

To list files sorted by modification time in MacOS using the ls command, execute the following command:

Terminal window
ls -t

How can I see only directories listed, excluding files in MacOS?

To see only directories listed, excluding files in MacOS using the ls command, execute the following command:

Terminal window
ls -d */

Applications of the ls command

  • Viewing files in a directory
  • Displaying file and folder permissions
  • Sorting files and folders by name, size, or last modified date
  • Displaying hidden files using the -a option
  • Showing more detailed information about files and folders with the -l option
  • Filtering files and folders by type or name using wildcards
  • Using different color schemes for file types and permissions
  • Displaying the total size of files in a directory
  • Viewing symbolic links with the -l option