Home Linux Shell script to display list of files in the current directory

Shell script to display list of files in the current directory

by Anup Maurya
5 minutes read

Shell script to display list of files in the current directory.

#!/bin/bash

echo "List of files in the current directory: "

for file in *; do
    echo $file
done

This script starts by printing a message indicating that it will list the files in the current directory. It then uses a for loop to iterate over all the files in the current directory (* is a wildcard that matches all filenames). For each file, it simply prints the filename.

You can save this script to a file, e.g. list_files.sh, make it executable using chmod +x list_files.sh, and run it with ./list_files.sh to see the list of files.

NOTE: ‘ls’ command in Linux lists all the files and directories.

Thank you for reading, If you have reached so far, please like the article, It will encourage me to write more such articles. Do share your valuable suggestions, I appreciate your honest feedback!

related posts

Leave a Comment