How do I list files in a directory?

QuestionsQuestions4 SkillsProBasic Files OperationsDec, 03 2025
0123

To list files in a directory in Linux, you can use the ls command. Here are some common usages:

Basic Command

  • List Files:
    ls
    
    This command will display the names of files and directories in your current working directory.

Detailed Listing

  • List with Details:
    ls -la
    
    The -l option provides a detailed listing, showing file permissions, number of links, owner, group, size, and modification date. The -a option includes hidden files (those starting with a dot).

Listing Files in a Specific Directory

  • Specify a Directory:
    ls /path/to/directory
    
    Replace /path/to/directory with the actual path of the directory you want to list. For example:
    ls /home/labex/project
    

Example

If you want to list all files, including hidden ones, in your home directory, you would run:

ls -la ~

Additional Options

  • Sort by Modification Time:

    ls -lt
    

    This lists files sorted by the time they were last modified, with the most recently modified files first.

  • Human-Readable Sizes:

    ls -lh
    

    This option shows file sizes in a human-readable format (e.g., KB, MB).

Feel free to try these commands in your terminal, and let me know if you have any questions or need further assistance!

0 Comments

no data
Be the first to share your comment!