Bash Listing Files List Files Without Using `ls`


Example

Use the Bash shell's filename expansion and brace expansion capabilities to obtain the filenames:

# display the files and directories that are in the current directory
printf "%s\n" *

# display only the directories in the current directory
printf "%s\n" */

# display only (some) image files
printf "%s\n" *.{gif,jpg,png}

To capture a list of files into a variable for processing, it is typically good practice to use a bash array:

files=( * )

# iterate over them
for file in "${files[@]}"; do
    echo "$file"
done