Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

This chapter is from the book

This chapter is from the book

View a List of Files in Subfolders

ls -R

You can also view the contents of several subdirectories with one command. Say you’re at a Linux Users Group (LUG) meeting and installations are occurring around you fast and furious. “Hey,” someone hollers out, “does anyone have an ISO image of the new Kubuntu that I can use?” You think you downloaded that recently, so to be sure, you run the following command (instead of ls -R, you could have also used ls --recursive):

$ ls -R ~/iso
/home/scott/iso:
debian-6.0.4-i386-CD-1.iso  knoppix  ubuntu

/home/scott/iso/knoppix:
KNOPPIX_V7.2.0CD-2013-06-16-EN.iso KNOPPIX_V7.4.2DVD-2014-09-28-EN.iso

/home/scott/iso/ubuntu:
kubuntu-15.04-desktop-amd64.iso ubuntu-15.04-desktop-amd64.iso
ubuntu-14.04.3-server-amd64.iso

There it is, in ~/iso/ubuntu: kubuntu-15.04-desktop-amd64.iso. The -R option traverses the iso directory recursively, showing you the contents of the main iso directory and every subdirectory as well. Each folder is introduced with its path—relative to the directory in which you started—followed by a colon, and then the items in that folder are listed. Keep in mind that the recursive option becomes less useful when you have many items in many subdirectories, as the listing goes on for screen after screen, making it hard to find the particular item for which you’re looking. Of course, if all you want to do is verify that there are many files and folders in a directory, it’s useful just to see everything stream by, but that won’t happen very often.

  • + Share This
  • 🔖 Save To Your Account