zaro

How do I see all folders in Linux?

Published in Linux Commands 4 mins read

The most fundamental way to see all folders (directories) and files in Linux is by using the ls command.

Understanding the ls Command

In Linux, the ls command is the primary utility used to display the contents of a directory. When executed, it outputs the names of files and directories within a specified location directly to your terminal. You can customize this output to show more details or filter specific types of entries by using various flags (options) with the command.

Listing Visible Folders

By default, ls shows all visible files and subdirectories within your current working directory.

  • To list the contents of the current directory:

    ls

    This will show a simple list of files and directories. Directories are typically displayed in a different color (depending on your terminal settings) or indicated by a trailing slash when using specific options.

  • To view directories and files with detailed information:
    Use the -l (long format) option. This provides comprehensive details such as file permissions, number of links, owner, group, size, and last modification date.

    ls -l

    In this output, directories are usually indicated by a d as the first character in the permissions string (e.g., drwxr-xr-x).

Including Hidden Folders

In Linux, files and directories that start with a dot (.) are considered hidden. These are typically configuration files or directories that you don't usually need to see during day-to-day operations.

  • To show all files and directories, including hidden ones:
    Use the -a (all) option.

    ls -a
  • To combine long format with hidden items:
    You can combine flags for more detailed output.

    ls -la
    # or
    ls -al

    This is one of the most commonly used combinations to get a full, detailed view of all contents in a directory.

Listing Only Directories

If you specifically want to see only the directories and exclude individual files in the current location, you can use a combination of options and wildcards.

  • To list only subdirectories (visible ones):

    ls -d */

    The */ wildcard matches all subdirectory names, and the -d (directory) option tells ls to list the directory itself rather than its contents.

  • To list all subdirectories, including hidden ones:

    ls -d */ .*/

    This command combines the wildcard for visible directories with one for hidden directories (those starting with a dot followed by any characters).

Exploring Subdirectories Recursively

Sometimes, "seeing all folders" means you want to view the entire directory tree from a specific point downwards.

  • To list the contents of subdirectories recursively:
    Use the -R (recursive) option. This command will list the contents of the specified directory and then recursively list the contents of any subdirectories it finds.

    ls -R
  • To get a detailed, recursive listing:
    Combine -l and -R:

    ls -lR

    Be aware that for large directory structures, this command can produce a very long output.

Key ls Options at a Glance

The following table summarizes the most useful ls options for viewing directories:

Option Description Example Command
-l Displays output in a long list format, showing permissions, owner, group, size, and modification date. ls -l
-a Lists all files and directories, including hidden ones (those starting with a dot .). ls -a
-R Recursively lists the content of subdirectories, showing the entire directory tree. ls -R
-d Lists directories themselves, not their contents, often used with wildcards to target directories. ls -d */
-h Displays file and directory sizes in a human-readable format (e.g., 1K, 234M, 2G). Often used with -l. ls -lh

Practical Tips

  • Combine Options: You can combine multiple ls options into a single command (e.g., ls -lah for a detailed, human-readable list of all files and directories, including hidden ones).
  • Specify a Path: To list folders in a directory other than your current one, append the directory path to the command (e.g., ls -l /home/username/documents).
  • Use tree command: For a more visual, tree-like representation of your directories, you can install the tree command (sudo apt install tree on Debian/Ubuntu or sudo yum install tree on CentOS/RHEL). Then, simply run tree or tree -a for all files.