How to show recursive directory listing on Linux or Unix

I am a new Linux system user. How do I see a recursive directory listing on macOS Unix system? In Linux, how can I get a recursive directory listing?

Introduction – If you like to receive the list, all directories and files recursively try the following commands.

What is a recursive listing of files?

Recursive means that Linux or Unix command works with the contains of directories, and if a directory has subdirectories and files, the command works on those files too (recursively). Say you have a directory structure as follows:
tree dir1

From the above outputs, it is clear that running the tree dir1 gives a list of dir1 directory and its subdirectories and files. The base directory is dir1. Then you have all the child directroies. All all the child directories have additional files and directories (say grand directories), and so on. You can use various Linux commands going through each directory recursively until it hits the end of the directory tree. At that point Linux commands come back up to a branch in the tree a does the same thing for any sub-directories if any.

How to get a recursive directory listing in Linux or Unix

Try any one of the following command:

  1. ls -R : Use the ls command to get recursive directory listing on Linux
  2. find /dir/ -print : Run the find command to see recursive directory listing in Linux
  3. du -a . : Execute the du command to view recursive directory listing on Unix

Let us see some examples to get a recursive directory listing in Unix or Linux systems.

Linux recursive directory listing command

Type the following command:
ls -R
ls -R /tmp/dir1

Linux recursive directory listing using ls -R command.

Unix recursive directory listing command

Since, not all versions of Linux, macOS, *BSD, and Unix-like system have -R option for the ls command. Try to use find command:
find . -print
find /tmp/dir1 -print
find /tmp/dir1/ -print -ls

Recursive directory listing in Linux or Unix using the find command

How to list all files recursively in a directory

Our final example uses the du command as follows:
du -a .
du -a /tmp/dir1/

You can also use the tree command as follows:
tree .
tree /tmp/dir1/

Recursively working with files

It is possible to run command recursively on files. The syntax is:
my-command-here $(find /dir/ -name 'pattern' -print)
rm -i $(find /home/nixcraft/ -name '*.bak' -print)

Of course, your can run command using find itself:
find /dir1/ -name 'pattern' -print -exec command ;
find /dir1/ -name 'pattern' -print -exec command {} ;
find /dir/2/foo/bar -name "*.pl" -exec rm -rivf {} \;
find /dir1/ -type f -name "*.doc" -exec rm -fiv {} \;
## find file recursively and delete them ##
find /dir1/ -name 'pattern' -print -delete

See “Linux / Unix: Find And Remove Files With One Command On Fly” for more info.


You learned how to list all files recursively in a directory under Linux, macOS, *BSD and Unix-like operating system using the ls, du, and find commands.

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Marlena Mar 23, 2018 @ 12:47

    Don’t forget grep. It has -r option too:
    grep -r "search" /dir/

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @