Written by
Connie YangSummary: This post introduces the ls command and its uses. Besides, you will also learn the differences between ls and ls -l, ls -a, and ls -al. - From iBoysoft
If you hear about the ls command or need to run it to proceed with some tasks but know nothing about it, you can follow our post to learn the ls command comprehensively.
What does the ls command do?
ls is a Linux command that displays all files and directories (except hidden ones) in the current directory. It can list the files in detail, including the file name, file type, and folder name.
The ls command can also be used in macOS but not in Windows. The ls command in Windows is different, it is the dir command.
Go to explain to others what the ls command means.
ls command options and examples
Here are some common ls command options and examples:
ls -l lists all files and directories in the current folder or directory with detailed information in a long list.
ls -a lists all files and directories including the hidden files in the current folder or directory.
ls -t sorts files and directories by modification time and lists them with the newest first.
ls -S sorts files and directories in the current directory by their sizes and lists the largest one first.
ls -h lists file sizes in human-readable formats (e.g., KB, MB) when combined with -l, in other words, ls -hl.
ls -r lists files and directories in the current directory in reverse of the default listing order.
ls -g lists the group ownership of files and directories instead of the owner in the current directory.
These ls command options can be used in combination.
ls vs. ls -l vs. ls -a vs. ls -al
The ls command and its common options ls -l, ls -a, and ls -al have slight differences. Let's compare them.
- ls lists all the files in the current folder or directory.
- ls -a lists all the files, including hidden files in the current folder or directory.
- ls -l lists the basic information of all the files in the current folder or directory in a long list format.
- ls -al is a combination of ls -a and ls -l. It lists the detailed information of all the files including the hidden files in the current directory in a long list.
How to use the ls command on Mac?
You can use the ls command and other ls command options on your Mac to list files in folders.
- Click Launchpad > Other > Terminal.
- Enter the path of the folder into the Terminal window. For example, enter cd ~/Documents to locate at the Documents folder on a Mac.
- Type ls into the window to list the files and subfolders in the target folder.
You can also type other ls command options according to your needs.
Note: To copy the pathname of the folder you want to list files, you can use iBoysoft MagicMenu. This right-click enhancer helps you right-click the folder to copy its pathname.
- Download, install, and open iBoysoft MagicMenu on your Mac.
- Click Extensions on the app's main interface. Find Copy Path from the Extension store and click the download button to add it to your right-click menu.
- Right-click any folder and select Copy Path to copy its pathname.
How to pause when using the ls command?
If you need to pause the output of the ls command during its execution, you can press the Ctrl + Z keys on your keyboard. Also, if you don't need the file details that are already listed, you can directly quit the process.
Share this post if you think it introduces the ls command comprehensively.