UNIX Recursive Directory Listing

Posted August 25, 2004 by Rex in UNIX

When listing the contents of a directory and all subdirectories, a recursive listing is sometimes useful. This tech-recipe describes techniques for listing files recursively.


The simplest method of performing a recursive directory listing is with the following ls command:

ls -R

ls -lR

The first is a short listing (filename only), and the second version shows a long listing (the output of ls -l, but recursive). These commands will perform the recursive listing from the current working directory. Adding a directory name to the end of the commands will start the listing in that directory.

The find command performs recursive searches by default. To duplicate ls -R, use the following:

find . -print

The -print option is the default in many versions of find, so just ‘find .’ will often work. The find command is extremely powerful, and learning more about it is worth your time. Recipes such as this are a useful reference for the topic.

The Conversation

Follow the reactions below and share your own thoughts.