The du Command In Linux

There’s always time for a basic article or two and today we’ll do that as we just play around with the du command in Linux. This is a functional tool and one you can learn to use in just a few minutes. Because of that, I’ll try to keep the article reasonably short.

Storage…

On Linux, everything is a file. These files are stored with a system – such as a particular formatting method like Ext4. Collectively, this is your file system.

Because of this, you may have done similar things, you’ll find that file sizes are all divisible by four. That’s because of the way things are stored. They’re stored in blocks and 4KB is (generally speaking) the smallest block you can have. So, it only makes sense that things can be divided by four.

Running out of storage space is A BAD THING®. It can even prevent you from booting! You do not want to run out of space on your drives. You don’t want to run out of space on any of your partitions.

When you installed Linux, you should have taken care to ensure that the partitions will be large enough for you to grow into. It’s possible to add storage. You can even modify your system to move your ~/home directory onto a partition all its own.

It’s easier to ensure you have enough room when you start. Storage space is relatively inexpensive these days. You can get really fast storage (such as an NVMe M.2 SSD) for little money. If your motherboard doesn’t support NVMe, you can get a cheap PCIe riser card to add that feature.

We’ll be using the du command to see how much space you’ve used.

The du Command:

The du command is a terminal-based application. You shouldn’t need to install anything for this article, it should be installed by default. We’ve previously used this command to sort files by size if you’re curious.

Anyhow, you can ensure du is available with the following terminal command:

Which should give you an output like this:

If you get an output similar to that, you’re good to go and won’t need to install anything to finish this article. The man page can be accessed with the following terminal command:

The output from that command should be a good indicator that we’re using one of the correct tools for the job. This being Linux, there are many choices. In this case, the du command is described as:

As you can tell by the introductory paragraphs, that’s a good tool for the task we’ve set for ourselves today. We want to see how much file space we’re using.

Using The du Command In Linux:

If you read the above paragraphs you’d know that this is another one of those things you do in the Linux terminal. Yes, there are graphical tools that will let you do this – but this way is universal. You’re going to find the du command on any Linux system you’re likely to touch. So, press CTRL + ALT + T and we can get going.

With your terminal open, you can just start with the basics:

That will show you the bytes used by the directories. We want to see the storage space consumed by directories and files, so we’ll add the -a flag to the following command:

That should show file and directory sizes in bytes. That’s not very readable by a human unless you want to do some math in your head. So instead we’re going to add the -h flag. Like so:

That’s all well and good. You can use cd to navigate around your computer or you can specify the path. How do you do that? Well, the syntax follows:

So, if we want to view the storage consumption of the ~/Downloads directory we’d simply use the following command:

Now, if you just want to see the total value of the directory you can use the following command with the -s flag:

If you want to find out how much storage space is consumed by your entire ~/home/<user> directory, that’s a very simple command:

I’d not suggest using the du command to check the entire drive of a running system. It will want to also calculate anything plugged into the computer and take forever. There are other ways to view drive usage information.

If you want to use a GUI, here’s a few tools for you:

A Few Ways To Visualize Disk Usage In Linux

There are innumerable ways to do this in the terminal and I’ve covered many of them. Most recently, I showed you a way to use Python to view disk usage. I admit my bias, but that’s a neat way to give you some basic information in a handy format that’s easily understood.

This is one of those things you can do with a multitude of tools. It is also a fairly basic task and something we should all be aware of. Know how much free storage you have and act accordingly.

Don’t wait for the drives to fill up before acting because that just makes it harder on you. You know the adage about how an ounce of prevention is better than a pound of cure? Well, keep that in mind when you think about your storage solutions.

Closure:

Oh, I’m sure I’ve mentioned the du command before. It sounds like something I’ve written about. I do know that I used it so that you could sort files by size, which is nice. At least I’m pretty sure I did…

At this point, who knows? I could do a lot of searching just to check, but the search doesn’t always do a good job and it’s too late now because I’ve written the article!

As of today, you should be fairly fluent in the du command. You might want to read the man page. There’s quite a bit that I didn’t cover. I only covered the basics. More specifically, I only covered the ways I use the du command. You may have very different needs. You may have a very different process. With that in mind, read the man page.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Show Your USB Devices In The Linux Terminal

Today’s article won’t be all that long or complicated because we’re just going to show your USB devices in the Linux terminal. This is something easily done and not something too unusual. You never know when you’ll want to show your USB devices, but this is your chance to do so.

We have covered the lsusb command in the past, but we’ll include that and go beyond that. Why? Because we can. It’s okay to revisit earlier material if we’re going to add to it.

USB stands for Universal Serial Bus and there are many versions. I’d like to think that my readers don’t need to be told what USB is. You’ve probably used USB devices in the past, including using a USB storage device to install Linux or use as an input device like your keyboard and mouse. 

Not having to explain that will save a lot of time!

Show Your USB Devices:

You can learn quite a bit about your USB devices in the terminal. You can learn what the devices are, maybe the product name, where it’s plugged in, and more. So, we’ll cover that in this article.

The two tools we’re going to use shouldn’t require any new software. Sweet!

lsusb:

The first tool we’ll cover is the lsusb application. You won’t need to install this. It will be installed by default. You can confirm that you have lsusb installed with the following command:

Sure enough, you can check the man page to see that this is a good tool for this task. That command is:

With that information, you can see that it’s described like this:

lsusb – list USB devices

See? It’s exactly the tool for the job!

To run this command, you simply run it in your terminal – like so:

That will output a bunch of USB information.

usb-devices:

Now this is a command that I’ve not previously covered. It’s a simple command to operate but the output is different from the above. This command gives a great deal more information than the above lsusb command does. 

You can ensure that usb-devices is installed with this command:

If you want to check the man page, run this command:

You’ll see that this is a useful tool if you want to show USB devices. In fact, you’ll see that it’s possibly better than the plain lsusb command. It’s described like:

usb-devices – print USB device details

The important part is ‘details’. This command will show you a great deal of the details regarding the USB devices.

NOTE: This will only show the details for things that are active. If you have inactive USB devices it will not show them. That explains the difference between the lsusb command and the usb-devices command. Well, that and this command spits out a lot more information.

If you want to run this command in your terminal, it’s simply done like so:

That’s not very complicated at all and will reveal quite a bit more information than you’d get with the previous lsusb command. It’s worth running both in some situations, but run this usb-devices command if you need detailed information.

Closure:

See? I told you that this one wouldn’t take all that long. I probably could have labeled this one as a short article, but I didn’t. It’s also written in a different format – not even telling you how to open your terminal. If you need to know that, you can figure it out – or you already know. I did mention the terminal in the headline.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

View Disk Usage

This article might seem like it has been written before but this is an entirely new way to view disk usage. To write this article I had to write two other articles. Tell me that that doesn’t sound like fun!

So, let’s see here… And, yes, I’m aware that they’re not disks anymore.

Yup. It’s official. There are too many ways to view disk usage in Linux – especially in the terminal. Why am I writing yet another article on the subject of disk usage? Because I can! I love showing how there are many ways to do the same thing in Linux. This is great because you can pick and use your favorite methods.

As for the subject of monitoring disk usage…

Monitor Disk Usage With GDU
Show Disk Usage With ‘ncdu’
A Few Ways To Visualize Disk Usage In Linux
How To: Check Disk Usage With ‘df’
Yet Another Way To Check Filesystem Space Use

Those are just the first five links when I searched for ‘disk usage’. That’s just five ways to check disk usage in Linux. I’m willing to bet that we can easily come up with five more ways to do this.

What’s special about this way of viewing disk usage?

Well, today we’ll be monitoring your drive space with a tool written in Python. You’ll need to enable PIP, a Python packaging tool. Once you’ve done that, this is universal. It will work in any distro that supports PIP – which, as you’ll see, is just about every major distro on the planet.

Read the following before going further:

Install Python’s PIP Part One
Install Python’s PIP Part Two

If you haven’t already installed Python’s PIP, this article will be of no use to you. You’ll need PIP enabled to proceed. You should also add the $PATH as defined in the second article. From here on out, the article will assume you’ve done both of those things.

View Disk Usage With Vizex:

The tool we’ll be using is known as Vizex. You can see the Vizex project page here. If you bother going there, you’ll see that Vizex is indeed the correct tool for the job. You’ll see that this is (one of the many) correct tools for the job.

vizex is the terminal program for the UNIX/Linux systems which helps the user to visualize the disk space usage for every partition and media on the user’s machine. vizex is highly customizable and can fit any user’s taste and preferences.

Hmm… It is at this point that I noticed that they don’t capitalize it. I’m going to capitalize it because it’s keeping the system from saying I didn’t spell it properly. 

Anyhow, as you’re using PIP, you’ll need an open terminal. You can use your GUI to open your terminal. On many systems, just press CTRL + ALT + T and your default terminal will open.

To install Vizex, run the following command:

If you’ve never installed a Python package with PIP before, then be sure to keep an eye on the screen. It’s a fascinating process and watching stuff happen in the terminal is pretty sweet!

Now that you have Vizex installed, you simply run that command in the terminal. If you didn’t follow the 2nd part of the Python PIP article you’ll have to specify the path. That’s just silly. Follow the 2nd article (it’s really easy) and you don’t have to deal with that. 

Using Vizex:

Anyhow, that command is simply:

It will even color-code your drives. If they’re close to full, they’ll be red and blink (missed in the screenshot below). If you’re moderately full, they’ll be listed in the yellow. I wanted to use Vizex to view a computer will all sorts of drives, so I did! That’s how you ended up with this screenshot:

using vizex to view disk usage
If this isn’t self-explanatory, I don’t know what is! It’s so simple that I can figure it out!

If that isn’t one of the easiest ways to view disk usage, I don’t know what is. This is just one of the many reasons why you should have Python’s PIP installed. There’s a bunch of software that’s available if you just know where to look. It took a while, but I finally got around to sharing this information. In my defense, it did take a couple of articles to share it properly.

Closure:

There are all sorts of ways to view disk usage. This is just another way, though it’s an interesting way. I’m quite sure that I’ll cover this very same subject again in another article. For now, I’ve covered a way to do so with Python and that’s something different than you’ve previously seen on the site.

I may not place ads on the site and just opt to accept sponsored articles as a way to cover the bills. That seems like a good thing to do. Some stuff may already be in the works, so look for that in the future. If you’re interested in sponsoring an article, be sure to hit me up. We get good traffic and rank well in the search engines. So, get some extra traffic and some SEO benefits by sponsoring an article!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Test Your Storage Drive’s Read Speed

One of the most frequent things you’ll do is read data from disk, so why not test your storage drive’s read speed? In this article, we’ll use an application we’ve used before. This shouldn’t be a very complicated article.

We store data on drives, or disks if you prefer. Most of us don’t use disks as our main storage devices. We do use disks for backups or storing large amounts of data, but we largely use SSDs these days. Some of us even use NVMe M.2 SSDs to store our data. The latter is currently the quickest you’re likely to encounter as a consumer.

The old spinning platters we used (though we’ve used lots of forms of magnetic storage) are typically referred to as HDDs (Hard Disk Drives). The SSDs (Solid State Drives) have no moving parts and are much faster. The NVMe M.2 SSDs are faster still.

If you’re suffering from some bottleneck, you might want to diagnose that. You might just be curious. It is also possible that you just purchased new hardware and want to see if the storage device reaches the advertised speed.

The tool we’ll be using is hdparm. This works fine with USB thumb drives, HDDs, regular SSDs, and even NVMe SSDs. It’s a complex application with a lot of options. I’ve covered some features before.

How To: Show Your Hard Drive Specifications In The Terminal

So then, let’s learn about this hdparm…

hdparm:

It should be noted that this hdparm application should be installed by default. It should also be mentioned that hdparm is a terminal-based application. You can verify that hdparm is installed with the following command:

If you then check the man page (with man hdparm) you’ll see that hdparm is described quite nicely like this:

hdparm – get/set SATA/IDE device parameters

If hdparm is not installed, you can surely find it in your package manager. 

As you can see, hdparm is the right tool for the job assuming you want to test your storage drive’s read speed. It’s also the right tool for a bunch of other jobs, but we’ll just be covering the read speed today.

Test Your Storage Drive’s Read Speed:

As I mentioned above, this hdparm application is something you use in your terminal. I suspect my regular readers will have guessed that. If you’re new to the terminal, more often than not you can open your default terminal by pressing CTRL + ALT + T.

With your terminal open, let’s identify your storage drives with this command:

You’re interested in the bits that start with /dev/<drive_ID> as those are the drives you’ll be able to test. 

NOTE: You should run these tests several times and average them, and you should do so while the system is otherwise idle. That will give you the peak results.

We’re interested in two flags, as they represent two tests. The -t flag tests the read cached. The -T flag tests the drive’s buffered read timings. You’ll often find the first test is fairly similar throughout the different drives and that the cached test shows the most differences. If those two terms, cached and buffered, confuse you, here’s a link about the differences between cache and buffer as far as the hdparm application goes.

You’ll need elevated permissions for this, so the command looks like this:

Or, as an example for many of you, the command might look like this:

That command will test both the cached read speed and the buffered read speed. These tests are important because you’re using a smart operating system that puts things into the cache and buffer that are likely to be read from the drive. So, the command listed will test both. You can split them up of course.

I decided to get you some examples:

Some Quick Read Speed Tests:

This is the internal SSD on a desktop:

Next is a USB 2.0 device plugged into that desktop:

Then we have an external HDD plugged into a USB 2.0 port on that desktop:

For comparison, this is an NVMe M.2 SSD:

As you can see, the internal SSD is quite fast. The thumb drive is the next quickest. This is followed by the external drive that’s just a spinning platter drive. 

Then, of course, you can see that the NVMe M.2 SSD is so much faster. That’s not even the fastest SSD out there. There are faster NVMe M.2 SSDs that don’t cost a lot of money. The prices have come down these days. You can even get a PCIe card that lets you mount an NVMe M.2 SSD if your motherboard doesn’t already support it.

Closure:

Should you want to get some drive benchmarks, you can certainly use hdparm to test your storage drive’s read speed. This isn’t something complicated and most anyone can figure it out. All you need to do is follow the directions carefully and in order. I do try to explain things as I go along.

There’s a lot more to the hdparm application. I encourage you to check the man page. There are probably another half-dozen articles that can be written about hdparm, so you’ll likely see this application again in the future. I doubt I’ll do another one too soon, as I like to space things out and not get too repetitive. 

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Yet Another Way To Check Filesystem Space Use

Many tools do the same thing in Linux and this is just another way to check filesystem space use. This one isn’t all that special, it’s just another way. If you want to check your filesystem usage (basically, how much free space you have used on your storage devices) this article can help you with that.

This shouldn’t be a long article. I’ve written others on the topic. It’s safe to assume that you know what a filesystem is. It’s the system your hardware uses to store data if you don’t know. There are many types, from Ext3 to ExFAT. They are all filesystems used to store data.

It should go without saying that you can fill up your storage space and might want to know how much space you have available. Well, if you want to find that information, this is an article for you!

This is another application. There are others.

Monitor Disk Usage With GDU
Show Disk Usage With ‘ncdu’
How To: Check Disk Usage With ‘df’

Those are just a few applications that will let you monitor your filesystem’s usage. I’m sure I’ve covered others.

This pydf is a Python script, but we’ll be using Lubunt and installing pydf just like we’d install any other application, albeit in the terminal. I will point out that pydf has a colored output, which is nice.

I can’t say that this pydf is available in other distros, but it’s available in Lubuntu. As Lubuntu is Ubuntu, that means it’s available in Ubuntu. It is also likely available in Debian. I think you’ll find that pydf is also available in the downstream distros like Linux Mint. I did provide a link above that will take you to the project page.

Check Filesystem Space Usage:

As I’ve done the work in Lubuntu, these directions will be for Lubuntu. You can adapt them easily. In Lubuntu, you can open the terminal by pressing CTRL + ALT + T on your keyboard. That will open the default terminal.

With your terminal now open, you can install pydf with the following command:

If you want to check the man page (say with man pydf), you’ll find that there isn’t one. If you’d like to view the pydf’s help file, try this command:

Once you’ve done that, you’ll see that using pydf is quite simple. If you just want to run the program to check filesystem space use, then just run it in the terminal like so:

If you want the output in ‘human-readable’ format, you can add a -h flag where bits are divided by 1024, or -H which means bits are divided by 1000. The choice is up to you.

Likewise, if you want to see even the zero-byte filesystems (the special filesystems that you don’t work directly with), you’d run this command:

Additionally, there’s a -l flag that limits the output to just the local filesystems. If I combine them for my preferred output, I get this:

Here’s an example output:

As you can see, there are a bunch of loop devices which are Snaps, which is perfectly normal for many Ubuntu-based systems. You can also see that I’ve used slightly more than half of my drive space and clever observers would notice that the drive is an NVMe SSD.

Closure:

So, that was a quick and easy article about how you can check filesystem space use, specifically in Lubuntu but easily applied to other distros. There are many ways to accomplish this task in Linux, which means this is just one among many such tools. It shouldn’t take too long to learn how to use pydf if that’s the tool you want to use.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.