Cheat Sheet #day42 - ls

Cloud TunedCloud Tuned
3 min read

ls Cheatsheet

Basic Usage

  • List Files and Directories

      ls
    
  • List Files and Directories with Details

      ls -l
    

Common Options

  • List All Files (Including Hidden)

      ls -a
    
  • List All Files with Details

      ls -la
    
  • List Files in Human-Readable Format

      ls -lh
    
  • List Files in Reverse Order

      ls -r
    
  • Sort Files by Modification Time

      ls -t
    
  • Sort Files by Size

      ls -S
    
  • Sort Files by Extension

      ls -X
    
  • Display Directory Entries Instead of Contents

      ls -d */
    
  • List Only Directories

      ls -d */
    
  • Colorize the Output

      ls --color=auto
    

Combining Options

  • List All Files, Including Hidden, with Human-Readable Sizes

      ls -lha
    
  • List Files Sorted by Modification Time with Details

      ls -lt
    
  • List Files Sorted by Size in Human-Readable Format

      ls -lhS
    
  • List Files with Details, Sorted by Extension

      ls -lX
    

Useful Tips

  • List Files with Detailed Information Including Timestamps

      ls -l --time-style=full-iso
    
  • List Files with Inode Numbers

      ls -i
    
  • List Files Recursively

      ls -R
    
  • List Files with Detailed Information Including File Type

      ls -F
    
  • List Only the File Names

      ls -1
    

Advanced Options

  • List Files with Contextual Information (like ls -l)

      ls -C
    
  • Group Directories First

      ls --group-directories-first
    
  • Ignore Certain Files

      ls --ignore="pattern"
    
  • Display Help for ls

      ls --help
    
  • List Files with Detailed Information Including Context

      ls -lc
    
  • List Files with Access Time

      ls -lu
    
  • List Files with Birth Time

      ls -lt --time=birth
    

Examples

  • List All Files in /etc Directory

      ls -a /etc
    
  • List Files in /var Directory in Human-Readable Format

      ls -lh /var
    
  • List Files in /home Directory Sorted by Modification Time

      ls -lt /home
    
  • List Files in Current Directory with Details and Sorted by Size

      ls -lS
    
  • List Files in Current Directory with Full Timestamps

      ls -l --time-style=full-iso
    
  • List Files in Current Directory with Inode Numbers

      ls -i
    
  • List Files in Current Directory Recursively

      ls -R
    
  • List Files in Current Directory with File Types

      ls -F
    

This cheatsheet covers essential commands and options for using ls effectively, from basic listing and formatting to advanced sorting and filtering. Adjust the commands according to your specific requirements and environment.

0
Subscribe to my newsletter

Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Cloud Tuned
Cloud Tuned