If you want to know the list of files in a directory you are in, you can use the ls command,
Example:ls
bin boot cocalc dev etc ext
home lib lib32 lib64 libx32
media mnt opt proc root run
sbin secrets srv sys tmp usr
var
Now lets try ls -l where -l: long listing format,
Example:ls -l
total 32
drwxr-xr-x 1 root root 87188 Aug 18 09:54 bin
drwxr-xr-x 2 root root 4096 Apr 24 2018 boot
drwxr-xr-x 1 root root 4096 Aug 12 20:40 cocalc
drwxr-xr-x 5 root root 360 Aug 22 09:59 dev
drwxr-xr-x 1 root root 4896 Aug 18 10:47 etc
drwxr-xr-x 1 root root 232 Aug 18 11:17 ext
drwxr-xr-x 1 root root 4096 Aug 12 20:40 home
drwxr-xr-x 1 root root 17526 Aug 18 09:53 lib
drwxr-xr-x 1 root root 2422 May 27 12:25 lib32
drwxr-xr-x 1 root root 40 May 25 12:51 lib64
drwxr-xr-x 1 root root 2544 May 27 12:25 libx32
drwxr-xr-x 2 root root 4096 Jul 13 14:48 media
drwxr-xr-x 2 root root 4096 Jul 13 14:48 mnt
drwxr-xr-x 1 root root 64 Jul 30 12:41 opt
dr-xr-xr-x 2313 root root 0 Aug 22 09:59 proc
drwx------ 2 root root 4096 Jul 13 14:49 root
drwxr-xr-x 1 root root 4096 Aug 12 20:40 run
drwxr-xr-x 1 root root 8994 Aug 18 09:53 sbin
drwxr-xr-x 4 root root 4096 Aug 22 09:59 secrets
drwxr-xr-x 1 root root 0 Apr 23 11:06 srv
dr-xr-xr-x 13 root root 0 Aug 22 09:59 sys
drwxrwxrwt 5 root root 100 Aug 22 10:02 tmp
drwxr-xr-x 1 root root 122 May 28 17:35 usr
drwxr-xr-x 1 root root 108 May 27 12:21 var
/$
How to display file or directory size using ls in KB, MB or GB?
In order to display file or directory size KBs (Kilobytes), MB (megabytes) or GB (gigabytes) you can make use the ls -lh command.
Example:/$ ls -lh
total 32K
drwxr-xr-x 1 root root 86G Aug 18 09:54 bin
drwxr-xr-x 2 root root 4.0K Apr 24 2018 boot
drwxr-xr-x 1 root root 4.0K Aug 12 20:40 cocalc
drwxr-xr-x 5 root root 360 Aug 22 09:59 dev
drwxr-xr-x 1 root root 4.8M Aug 18 10:47 etc
drwxr-xr-x 1 root root 232 Aug 18 11:17 ext
drwxr-xr-x 1 root root 4.0K Aug 12 20:40 home
drwxr-xr-x 1 root root 18K Aug 18 09:53 lib
drwxr-xr-x 1 root root 2.4K May 27 12:25 lib32
drwxr-xr-x 1 root root 40 May 25 12:51 lib64
drwxr-xr-x 1 root root 2.5K May 27 12:25 libx32
drwxr-xr-x 2 root root 4.0K Jul 13 14:48 media
drwxr-xr-x 2 root root 4.0K Jul 13 14:48 mnt
drwxr-xr-x 1 root root 64 Jul 30 12:41 opt
dr-xr-xr-x 2230 root root 0 Aug 22 09:59 proc
drwx------ 2 root root 4.0K Jul 13 14:49 root
drwxr-xr-x 1 root root 4.0K Aug 12 20:40 run
drwxr-xr-x 1 root root 8.8K Aug 18 09:53 sbin
drwxr-xr-x 4 root root 4.0K Aug 22 09:59 secrets
drwxr-xr-x 1 root root 0 Apr 23 11:06 srv
dr-xr-xr-x 13 root root 0 Aug 22 09:59 sys
drwxrwxrwt 5 root root 100 Aug 22 10:04 tmp
drwxr-xr-x 1 root root 122 May 28 17:35 usr
drwxr-xr-x 1 root root 108 May 27 12:21 var
/$
Note that now the sizes are displayed with a number followed by K -> Kilobytes where every you do not see K the size are in bytes.
⛏️ This command will work on all flavors of Linux, Unix, macOS and Windows Bash Shell.
More Posts related to MacOS,
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
More Posts:
- How to Convert a Notepad++ file to an Excel File - NotepadPlusPlus
- Clearing the Cache in Firefox Web Browser - HowTos
- How to mute all sounds in Notepad++ - NotepadPlusPlus
- Java Thread.sleep() Method Deep Dive with Examples - Java
- Fix - zsh: command not found: conda [macOS] - zsh
- How to create an Optional from existing Object in Java? - Java
- [macOS] Change homepage Macbook Safari Browser - MacOS
- How to Open Private Browsing (Incognito Mode) in Safari on Mac - MacOS