How to write a shell script to list files in a directory recursively. Linux shell scripts are group of commands. Usually we print list of files and directory in present working directory. To list files and directory we use ls command. ‘ls -R’ commands recursively list all files.

shell script to list files in a directory recursively based on ls command

  • Create a file
  • Write following code

  • Make executable using command ‘chmod +x
  • Run your script using command ‘sh’
  • You will see output like below

The output of shell script program contains a “.”. The dot (.) means current directory. The above scripts will print all files and directories. we can use find command to list all files in a directory recursively. See below example shell scrips.

Run using


It will list all files from current working directory and subdirectory .find . -type f ,passing -type f ignores the name of directory. There are many other way to list files. Try to learn more option from linux manual page for find and ls command¬† using ‘man ls’ command.

Related Contents to follow