What other commands can list directory contents?

QuestionsQuestions8 SkillsProDec, 14 2025
0118

That's a great question! While ls is the most common and versatile command for listing directory contents, there are a few other ways or commands that can give you similar or more specific information:

  1. dir:
    This command is actually an alias or sometimes a link to ls on many Linux systems. Its behavior is very similar to ls.

    dir
    dir -l  # Same as ls -l
  2. vdir:
    Similar to dir, vdir is often aliased to ls -l by default, providing a detailed, "long format" listing.

    vdir
  3. find (with specific options):
    While find is primarily used to search for files and directories, you can use it to list contents of a directory. It's more powerful for recursive listing or finding items matching certain criteria.
    To list everything one level deep (non-recursively, similar to ls):

    find . -maxdepth 1 -print

    This will print the current directory (.) and all its immediate contents. It includes hidden files by default.

  4. tree (if installed):
    The tree command is not always installed by default but is excellent for visualizing directory contents in a tree-like format, showing subdirectories and files.

    tree
    tree -L 2 # To limit the depth of the tree to 2 levels

    (You might need to install it first using sudo apt install tree if it's not available in your LabEx VM.)

  5. du (Disk Usage) with specific options:
    du is primarily for reporting disk space usage, but when used with certain options, it can effectively list directories and their sizes. Not ideal for just listing names, but useful if you also care about size.

    du -h --max-depth=1 . # Summarizes disk usage for current directory and its immediate subdirectories/files in human-readable format

For general purpose listing, ls is almost always your go-to command. find is powerful for more complex searches, and tree is fantastic for visual representation.

Is there a specific type of listing or information you're looking for that ls isn't providing?

0 Comments

no data
Be the first to share your comment!