shell command to list all files in a directory code example

Example 1: display all files in a directory linux

ls command list computer files in a directory in Unix OS with next structure:
ls [OPTION]... [FILE]...
Examples:
ls -l #display all files in current directory with  (-l) long format.
ls -a /directory #display all hidden files in given directory that start with .

Example 2: bash how to print the list of files in a directory

# Basic syntax:
ls /path/to/directory/

# Example usage 1:
ls /path/to/directory/ > output_file.txt # Write the files to an output
# Example usage 2:
ls /path/to/directory/ | grep *.txt > output_file.txt # Write the subset
# of files that match the grep search (e.g. end in .txt)