Another Way To View Attached Storage Devices

Linux offers myriad ways to accomplish the same task, which is a good thing, and this is another way to view attached storage devices. This is a useful way to learn more about your storage devices and is a bit more advanced than others.

There are many ways to view attached storage devices. While not the same, you can learn which storage devices are attached to your system with any of the following articles:

Show Your Filesystem In The Linux Terminal
Show Mounted Partitions
How To: List Mounted Partitions
Yet Another Way To Check Filesystem Space Use

Stuff like that…

Well, you can also just plain old view attached storage devices in the Linux terminal. The application I’ll be showing you will do more than this, but we’ll concentrate on just showing attached storage devices.

The tool we’ll be using is known as:

lsscsi:

Yes, we’ll be making use of the lsscsi application for this article. This won’t take very long and you should find that lsscsi is available for pretty much every operating system out there. It does what you’d think, list SCSI devices.

Once installed, you could check the man page to see that this is the correct tool if your goal is to view attached storage devices. The man page describes the lsscsi application like this:

lsscsi – list SCSI devices (or hosts), list NVMe devices

It’s a simple application, at least for our needs. You’ll find that you can get some of the same information with the following command:

However, that command won’t give you things like the path. Mounted storage devices tend to have a path of something like /dev/<path>, and that information isn’t available with the cat command listed above. As we often want to know the path information, and there are many tools to do this, you might as well learn about lsscsi. 

By the way, your GUI disk manager (such as gnome-disks) will happily give you some of this information. It’s also a graphical environment, which may be easier for some folks. This is for those needing that information while using the terminal, or for those who are just interested in doing more in the terminal.

But, when it comes to disk and data management, you may need to know this information – especially the paths. So, this is a good command to have in your pocket. You never know when it will come in handy.

View Attached Storage Devices:

If you’re unfamiliar with the lsscsi application, it’s a terminal-based application. If you’re already familiar with the lsscsi application, I’m not sure why you’re still reading the article! Either way now is the time when you open a terminal. Oftentimes, you can open a terminal by just using your keyboard. Try pressing CTRL + ALT + T and your default terminal should open.

With your terminal now open, it’s time to install lsscsi. The directions to do so will depend on your package manager, but I’m going to cover most of them because this application is widely available and packaged for almost anything you can think of.

Installing lsscsi:

With your terminal open, use the correct command for your package manager:

Debian/Ubuntu/etc:

RHEL/CentOS/etc:

Gentoo:

OpenSUSE/SUSE/etc:

Arch/Manjaro/etc:

One of those should work for most of you. If not, let me know in the comments and I’ll amend the application. If they’re wrong, please do let me know in the comments. I did not test all of these. I’m going with a combination of my notes and what I’m able to scrape from the internet.

Using lsscsi:

With that open terminal, just enter the name of the command and you have about all the use you’ll really need from the application. The command is simply:

If you want, there’s more to the application – which you might need for some advanced operations. You can just check the man page with this command:

Here’s an example output:

Here’s another example output:

If you look at the bottom one, there’s a bit of an Easter Egg. You’ll see that it starts with an N and that means it’s an NVMe device. You don’t need any special tools beyond lsscsi to view NVMe devices, which is nice. The program happily recognizes it and other attached storage devices.

Closure:

You never know when you’re going to want to view attached storage devices. However, the odds are good that you’ll eventually want to know this information. It’s always good to verify the path of a dd command, for example. A malformed command can really cause you some problems.

So, now you know how to view attached storage devices – a task that has many solutions in Linux. There’s nothing wrong with variety and each of the various tools will have different strengths. Knowing what to use and when to use it is something you’ll learn as you make progress.

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.

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.

Get Your NVMe SSD Information

If you’re using a modern computer, you might be using an NVMe SSD and you might want to know your NVMe information. The standard and older tools may not be all that helpful, even though NVMe SSDs have been around for a while. This article will help you with that, should you want to get your NVMe SSD information.

Let me see if I can explain this…

You’ll often see “NVMe M.2 SSD”, which is a mouthful.

NVMe stands for Non-Volatile Memory Express which is just a specification.

M.2 is another specification for expansion cards.

The device that is used for NVMe is an SSD – Solid State Drive.

SSD, which has been around for quite a while now, differs from previous generations of storage in that it’s electronic and not magnetic. 

We humans have a long history of trying to record things. We’ve used everything from words to pictures, from dots on paper to grooves on wire, from symbols to magnetic, and more…

For computers, a long time was in the magnetic storage age. From spinning drums holding mere bytes of data to complicated spinning platters that hold terabytes of data… We’ve made good use of the magnetic storage mediums over the years.

Solid-state drives don’t use magnets. Data is stored on memory chips that retain their memory (non-volatile) even if the power is disconnected. An SSD is quite common today.

Less common, but growing in popularity, is the NVMe M.2 SSD. This is a much smaller format than the early SSDs (which even came in the 3.5″ format, and surely some obscure formats that I’m overlooking). This is also on a faster bus lane, meaning the read and write speeds far exceed the storage medium before it – including the aforementioned larger SSDs that connect via IDE or (preferably) SATA.

The current consumer options are pretty great and an NVMe SSD is much faster than a regular SSD. The standard SATA SSD is quite common still, while the NVMe M.2 SSD is the latest and greatest.

With me so far?

Well, an NVMe M.2 SSD is a very different architecture and, as such, there are special tools to use. If you want to find the temperature of your NVMe SSD, the normal tools (like hdparm) may not yet work. Instead, there are other tools that you’d want to use.

In this article, we’ll be talking about a tool known as ‘nvme-cli’…

About nvme-cli:

You almost certainly don’t have nvme-cli installed by default. If you did, you’d be able to check the man page. Doing so would show that nvme-cli is described like this:

nvme – the NVMe storage command line interface utility (nvme-cli)

It should be important to know (and we’ll get to the installation step in just a minute) that you’ll be installing the package with one name but referring to, that is using, the application with another name.

For example, it’s man nvme to access the man page. 

NOTE: You will want to read the man page. There’s a whole lot of options and we’re just going to cover one basic command. We’ll learn stuff like the operating temperature of your NVMe. We won’t be worried about the various other options, of which there are many.

Find Your NVMe Information:

If you want to find your NVMe information in the terminal, you can do that. You’ll first need to install a tool known as nvme-cli. To do this, you’ll want an open terminal. You can usually open a terminal by just pressing CTRL + ALT + T

With your terminal now open, you must first install nvme-cli. You’ll find that packages are available for many distros, as they should be as the format is becoming more and more popular. 

Follow one of the basic installation methods below, specifically the one suitable for your distro’s package management system.

Debian/Ubuntu/etc:

SUSE/OpenSUSE/etc:

Fedora/Asahi/etc:

RHEL/CentOS/etc (those with yum available still):

Arch/Manjaro/etc:

I’m pretty sure there’s an nvme-cli package available for all the major Linux distros. If not, I linked to the project page above and you can check there for a package or to compile nvme-cli from source.

Find Your NVMe’s Absolute Path:

You’re going to need the absolute path to where your drive is mounted. That’s a part of the command, so you’ll need that. Just to mix things up a little bit, we’ll use the ‘df’ command. You should have df installed automatically on any major distro. The man page will helpfully describe the df application like so:

df – report file system disk space usage

We don’t care about all that. We just care about the absolute path. This usually starts with /dev/ and ends with the device ID. In an NVMe’s case, it will usually include nvme in the title, which is quite helpful.

So, let’s get that information…

You’ll get an output similar to this one:

It should be obvious that the absolute path for this would be /dev/nvme0n1p1 and that’s the data we’re going to need.

Now, to find your NVMe information, the syntax would be like so:

Using the output from above, an example of that would be:

This will then give you an output like so:

nvme status in the terminanl
There you go, you now have your NVMe Information. It’s not too difficult to do.

Of course, you can pipe this output to other commands. Let’s say you wanted to know the current temperature of your NVMe SSD. You’d do that with the grep command. An example would be:

If you want to know the number of times you’ve powered the device on, you can do that by piping the output to grep again. For example:

So, you can use the nvme-cli application (the nvme command) for quite a bit. You can do a whole lot more with it, so be sure to check the man page if you’re interested in doing more than checking the temperature or how many times you’ve cycled the power on that device.

As NVMe SSDs get more common, you’ll likely start seeing this package installed by default. From what I can see right now, no major distro is including this by default. If you’re using an NVMe M.2 SSD, you might just want to install it. If nothing else, it’s yet another tool that might come in handy.

Closure:

Today’s article is a bit longer than some but I think it’s worth reading. If I didn’t think it was worth reading, I wouldn’t have written as much! There’s so much that I could have covered but I didn’t. Articles have to have only so many words before people lose interest.

I’d have loved to cover the history of computer memory (or perhaps even more about how we humans have recorded stuff) but that didn’t seem prudent. I figured I’d limit the number of words to 1,200, but I still managed to exceed that – though not by too many. Seriously, it’s a pretty fascinating bit of history. You should use Google (and/or YouTube) to see learn about all the different ways we’ve stored data, and that’s just scratching the surface!

Fascinating stuff, I tell you! Fascinating!

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.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.