bash | | node webdriver support | Search

The command displays the names of the 10 largest files in the current directory, including their sizes, by using a pipeline of Unix utilities (du, sort, and head). The command includes file counting, numerical sorting, and reversing the order to show the largest files first.

Cell 0

du -a . | sort -n -r | head -n 10

What the code could have been:

#!/bin/bash

# Define a function to calculate disk usage
disk_usage() {
  # Use du to calculate disk usage of the current directory
  local disk_usage_output
  disk_usage_output=$(du -a. | sort -n -r | head -n 10)

  # Display the top 10 largest files in human-readable format
  echo "$disk_usage_output"
}

# Call the function to display the disk usage
disk_usage

Command Overview

The given command is a pipeline of Unix utilities used to display the 10 largest files in the current directory.

Breakdown

Effect

This command displays the names of the 10 largest files in the current directory, including their sizes.