File and Disk Usage

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux dd, df, and du commands. These commands are commonly used for managing and monitoring disk usage on a Linux system.

Achievements

  • dd - copy and convert files
  • df - report file system disk space usage
  • du - estimate file space usage

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL shell(("`Shell`")) -.-> shell/ControlFlowGroup(["`Control Flow`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) shell(("`Shell`")) -.-> shell/VariableHandlingGroup(["`Variable Handling`"]) shell/ControlFlowGroup -.-> shell/if_else("`If-Else Statements`") linux/SystemInformationandMonitoringGroup -.-> linux/dd("`File Converting/Copying`") linux/SystemInformationandMonitoringGroup -.-> linux/df("`Disk Space Reporting`") linux/SystemInformationandMonitoringGroup -.-> linux/du("`File Space Estimating`") shell/VariableHandlingGroup -.-> shell/variables_decl("`Variable Declaration`") subgraph Lab Skills shell/if_else -.-> lab-38{{"`File and Disk Usage`"}} linux/dd -.-> lab-38{{"`File and Disk Usage`"}} linux/df -.-> lab-38{{"`File and Disk Usage`"}} linux/du -.-> lab-38{{"`File and Disk Usage`"}} shell/variables_decl -.-> lab-38{{"`File and Disk Usage`"}} end

Creating and Manipulating Disk

The dd command is used for creating and manipulating disk images. It can be used for a variety of tasks, such as creating backups of entire partitions or copying the contents of one file to another.

dd command have 4 main parameters:

  • if - input file or device
  • of - output file or device
  • bs - block size
  • count - number of blocks to copy

Here is an example of using dd to create a 1000MB file named 1000.bin of a partition:

the /dev/zero device is a special device that generates a stream of zeros. It is used for creating empty files.

dd if=/dev/zero of=1000.bin bs=1M count=1000

Display the Amount of Available Disk Space

The df command is used to display the amount of available disk space on a Linux system. It can be used to check the available space on a specific partition, or to check the overall space available on all partitions.

Here is an example of using df to check the all available space:

df -h

The -h is a command-line option that tells df to display the available space in a human-readable format.

df command can also be used to check the available space on a specific partition. Here is an example of using df to check the available space on the /dev/sda2 partition:

df -h /dev/sda2

This command will display the available space on the /dev/sda2 partition in a human-readable format.

Display the Amount of Disk Space Used

The du command is used to display the amount of disk space used by a specific directory or file. It can be used to check the space used by a specific file or directory, or to check the space used by all files and directories in a specific location.

Here is an example of using du to check the space used by a specific directory:

du -h /home/labex

This command will display the space used by the specified directory in a human-readable format.

Summary

In this lab, we learned about the Linux dd, df, and du commands. We explored how to use these commands for creating and manipulating disk images, checking available disk space, and checking the space used by specific files and directories. We also saw some advanced examples of these commands. Remember that these commands are very powerful and should be used with care.

Other Linux Tutorials you may like