**Useful Command Line Code – Disk Usage (Linux/Mac):** If you ever need to quickly check how much disk space is being used in your current directory, you can use the `du -sh` command in the terminal

**Useful Command Line Code – Disk Usage (Linux/Mac)**

Disk space is a precious commodity, especially for users who juggle large amounts of data. Knowing how to manage and check disk usage can save you from a lot of trouble. In Linux and Mac systems, there’s a handy little tool in the command line where you can quickly check the disk usage of your current directory. It’s the `du` command, and when combined with the `-sh` option, it becomes a powerful ally.

## What is `du`?

The `du` command, short for ‘disk usage’, reports the estimated amount of disk space used by given files or directories. By default, it displays the disk space usage in bytes. However, the output can be less than intuitive to read, especially when dealing with large files or directories. This is where the `-sh` options come in.

## What does `-sh` do?

The `-s` and `-h` are options that modify the output of the `du` command.

– The `-s` (or `–summarize`) option tells `du` to display only a total for each argument. This means it will return the total disk usage of the directory, not the individual files within it.

– The `-h` (or `–human-readable`) option prints sizes in human-readable format. This means it converts the size into bytes (B), kilobytes (KB), megabytes (MB), gigabytes (GB), etc., making it easier to interpret the output.

## How to Use `du -sh`

1. **Open the terminal.** The terminal can typically be found in the Applications/Utilities folder on Mac, or in the Applications/Accessories folder on Linux. You can also use search functions to find it: Spotlight (Command + Space) on Mac, or Dash on Ubuntu (Super key, also known as the Windows key).

2. **Navigate to the directory you want to check.** You can do this using the `cd` (change directory) command. For instance, if you want to check the disk usage of a directory named ‘Documents’, you would type `cd Documents`.

3. **Run the `du -sh` command.** Once you’re in the directory you want to check, type `du -sh` and hit Enter. The terminal will then display the total disk usage of the current directory in a human-readable format.

For example:

“`bash
$ du -sh
1.5G .
“`

This output means that the current directory is using 1.5 gigabytes of disk space.

## Conclusion

The `du -sh` command is a simple but powerful tool for quickly checking disk usage in Linux and Mac systems. It’s easy to use and provides output in a format that’s easy to understand. So, the next time you need a quick check on your disk usage, remember this useful command line code.