OS lab 4 - 4b "df,du commands"
Working Directory Setup
Importance of being in the correct working directory before issuing commands.
Disk Usage Command: df
The command
dfis utilized to output the usage of drives within the specified folder.Focus is on the line that begins with a slash, denoting the root folder of the hard drive.
Key Outputs of df
Outputs the following details:
Used Bytes: Indicates the number of bytes currently utilized on the drive.
Available Bytes: Indicates the number of bytes available for use on the drive.
Improved Readability with -h Option
To enhance readability, the command can be modified to
df -h.The
hstands for "human-readable" format.After executing
df -h, outputs example:14 gigabytes of used hard disk space
39 gigabytes of available disk space
Benefits of Using df -h
Provides immediate information about disk space without navigating through a file explorer.
Simplifies the process of checking disk space to a single command.
Disk Usage of Folders: du
The command
duis used to determine the size of all folders in the current directory.duprovides insight into what is occupying disk space within the folder.
Enhanced Readability with -h
The command can be altered to
du -hfor a human-readable output on folder sizes.For example, running
du -hmay show:Lesson Four file is taking 336 KB
Total size for the Lesson Four directory is 360 KB
Recursive vs Summary Output
By default,
dudoes a recursive evaluation of folder sizes, which includes all subdirectories and files.To get a summarized view, the command can be modified to
du -sh:This will return the total size of the current directory.
For instance:
If executed, it may show the current directory takes 424 KB.
Summary of Disk Usage with Wildcards
To examine sizes of all directories, use
du -sh *:The asterisk (*) represents all files and directories in the current folder.
Example output:
Lesson One takes 80 KB
Lesson Two takes 12 KB
Lesson Four is largest, occupying 360 KB.
Practical Application
Utilizing
du -sh *can assist in identifying which files or directories occupy substantial disk space.In case of limited disk space, this command allows users to target specific large files or folders for deletion without needing additional software.