How to Get a Recursive Directory Listing in Linux

This post will guide you how to show a recursive directory listing in a Linux system. How do I display directories recursively on a CentOS or RHEL Linux.

Show Recursive Directory Listing


If you want to list all files under a given directory and its all subdirectories in Linux, and you can use one of the following command:

$ ls -R
$ find directory -print
$ du -a
$ tree directory

For example, you want to get a recursive directory listing for /boot directory, just issuing one of the following command:

$ ls -R /boot

Or

$ sudo find /boot -print

Or

$ du -a /boot

Or

$ tree /boot

Outputs:

devops@devops:~$ ls -R /boot
/boot:
config-5.0.0-25-generic memtest86+.elf
config-5.0.0-27-generic memtest86+_multiboot.bin
grub System.map-5.0.0-25-generic
initrd.img-5.0.0-25-generic System.map-5.0.0-27-generic
initrd.img-5.0.0-27-generic vmlinuz-5.0.0-25-generic
memtest86+.bin vmlinuz-5.0.0-27-generic
/boot/grub:
fonts gfxblacklist.txt grub.cfg grubenv i386-pc locale unicode.pf2
/boot/grub/fonts:
unicode.pf2
/boot/grub/i386-pc:
915resolution.mod gcry_tiger.mod password.mod
……
devops@devops:~$ sudo find /boot -print
[sudo] password for devops:
/boot
/boot/System.map-5.0.0-27-generic
/boot/config-5.0.0-27-generic
/boot/grub
/boot/grub/grubenv
/boot/grub/unicode.pf2
/boot/grub/grub.cfg
/boot/grub/gfxblacklist.txt
/boot/grub/locale
/boot/grub/locale/en_AU.mo
/boot/grub/locale/en@quot.mo
/boot/grub/locale/en_CA.mo
/boot/grub/locale/en_GB.mo
/boot/grub/i386-pc
/boot/grub/i386-pc/partmap.lst
/boot/grub/i386-pc/setjmp_test.mod
/boot/grub/i386-pc/setjmp.mod
/boot/grub/i386-pc/exfctest.mod
/boot/grub/i386-pc/lsmmap.mod
/boot/grub/i386-pc/div_test.mod
/boot/grub/i386-pc/ufs1.mod
/boot/grub/i386-pc/setpci.mod
/boot/grub/i386-pc/disk.mod
/boot/grub/i386-pc/search_fs_file.mod
……
devops@devops:~$ du -a /boot
4192 /boot/System.map-5.0.0-27-generic
220 /boot/config-5.0.0-27-generic
4 /boot/grub/grubenv
2344 /boot/grub/unicode.pf2
12 /boot/grub/grub.cfg
4 /boot/grub/gfxblacklist.txt
4 /boot/grub/locale/en_AU.mo
120 /boot/grub/locale/en@quot.mo
4 /boot/grub/locale/en_CA.mo
8 /boot/grub/locale/en_GB.mo
140 /boot/grub/locale
4 /boot/grub/i386-pc/partmap.ls
……
devops@devops:~$ tree /boot
/boot
├── config-5.0.0-25-generic
├── config-5.0.0-27-generic
├── grub
│ ├── fonts
│ │ └── unicode.pf2
│ ├── gfxblacklist.txt
│ ├── grub.cfg
│ ├── grubenv
│ ├── i386-pc
│ │ ├── 915resolution.mod
│ │ ├── acpi.mod
│ │ ├── adler32.mod
│ │ ├── affs.mod

If you want to see more information about those Linux commands, and you can run the following man command to check its manual help pager.

$ man ls
$ man du
$ man find
$ man tree

Conclusion


You should know that how to show all files recursively in a given directory under CentOS or RHEL or Ubuntu Linux operating system.

You might also like:

Sidebar



back to top