The command to list files in bash shell is "ls".
Few Examples of ls command usage:
Get the list of all files in the current directory
# ls Annual-Queries-2023.xlsx Archive-2020-2030 prod-script.py Archive-2010-2020 ToDo-List.txt satge-script.py
Get the list of all the files and directories in the current directory with more details.
# ls -l total 0 -rw-r--r--@ 1 c2ctech staff 0 May 4 21:46 Annual-Queries-2023.xlsx drwxr-xr-x@ 2 c2ctech staff 64 May 4 21:46 Archive-2010-2020 drwxr-xr-x@ 2 c2ctech staff 64 May 4 21:47 Archive-2020-2030 -rw-r--r--@ 1 c2ctech staff 0 May 4 21:46 ToDo-List.txt -rw-r--r-- 1 c2ctech staff 0 May 4 21:48 prod-script.py -rw-r--r-- 1 c2ctech staff 0 May 4 21:48 satge-script.py
Get the list of all files including hidden ones
# ls -la total 0 drwxr-xr-x@ 11 c2ctech staff 352 May 4 21:50 . drwx------@ 17 c2ctech staff 544 May 4 21:48 .. -rw-r--r-- 1 c2ctech staff 234 May 4 21:50 .config -rw-r--r-- 1 c2ctech staff 0 May 4 21:50 .secret-records.csv drwxr-xr-x 2 c2ctech staff 3264 May 4 21:50 .unclassified -rw-r--r--@ 1 c2ctech staff 0 May 4 21:46 Annual-Queries-2023.xlsx drwxr-xr-x@ 2 c2ctech staff 26341 May 4 21:46 Archive-2010-2020 drwxr-xr-x@ 2 c2ctech staff 62341 May 4 21:47 Archive-2020-2030 -rw-r--r--@ 1 c2ctech staff 0 May 4 21:46 ToDo-List.txt -rw-r--r-- 1 c2ctech staff 0 May 4 21:48 prod-script.py -rw-r--r-- 1 c2ctech staff 0 May 4 21:48 satge-script.py
Get all files and directories details in human-readable file sizes.
# ls -lh total 0 -rw-r--r--@ 1 c2ctech staff 12K May 4 21:46 Annual-Queries-2023.xlsx drwxr-xr-x@ 2 c2ctech staff 23K May 4 21:46 Archive-2010-2020 drwxr-xr-x@ 2 c2ctech staff 64B May 4 21:47 Archive-2020-2030 -rw-r--r--@ 1 c2ctech staff 1M May 4 21:46 ToDo-List.txt -rw-r--r-- 1 c2ctech staff 134B May 4 21:48 prod-script.py -rw-r--r-- 1 c2ctech staff 243B May 4 21:48 satge-script.py
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to Bash,
- How to use Autocomplete and Autosuggestion in Shell Commands
- Bash How to Save Output of a Command to a Variable
- How to know the current shell you are logged in?
- How to Echo Bash Command to a File
- Bash Command to Get Absolute Path for a File
- How to Split a String based on Delimiter in Bash Scripting
- Bash: Command Line Arguments to Bash Script Examples
- Bash Command to Download a File From URL
- How to check if a Command Exists using Bash Script
- Ways to Increment a counter variable in Bash Script
- Know Bash shell version command
- Bash command to Read, Output and Manipulate JSON File
- Bash Command to Base64 Decode a String
- Bash Command to Check Python Version
- Bash: Command to Find the Length of a String
- What is $$ in Bash Shell Script- Special Variable
- Bash - How to check if a Command Failed?
- List all Username and User ID using Bash Command
- Command to Sort File In Reverse Order [Unix/Linux/macOS]
- bash: netstat: command not found
- Bash Command To Go Back To Previous Directory
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory
- How to check your IP using bash for Windows?
- Bash Command To Check If File Exists
- Convert String from uppercase to lowercase in Bash
More Posts:
- How to Clear Mac Terminal History - MacOS
- Audio Video Network protocols supported by Android OS Devices - Android
- The Zsh Shell - Mac Tutorial - MacOS
- Channel 50 SMSes received every few minutes Android Phones - Android
- Fix - Error:Invalid Gradle JDK configuration found (Android Studio) - Gradle
- ChatGPT Outage: Hmm...something seems to have gone wrong. Maybe try me again in a little bit. - HowTos
- Setup synonyms or alias or thesaurus in SharePoint - SharePoint
- How To Remove Only Conditional Formatting in Excel - Microsoft