List Files Without Using ls

suggest change

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents