From the course: Linux Troubleshooting at the Command Line

Troubleshooting disk utilization - Linux Tutorial

From the course: Linux Troubleshooting at the Command Line

Troubleshooting disk utilization

- [Person] In this session, we're going to tackle diagnosing disc utilization issues on a Linux system. Running out of space can cause a range of problems, so it's crucial to pinpoint the source quickly. First, let's look at the overall disc space usage. For this, we'll use the "df" command, which stands for "disc free." To display the disc usage in human-readable format, we'll use "df -h," as you can see. The "h" flag translates the data into kilobytes, megabytes, gigabytes, making it easier to interpret. Here, you'll see details like the total size, use space, available space, and the percentage of usage for each mounted file system. From this, we can quickly identify which file systems are running low on space. Once we know which file system is nearly full, the next step is to drill down and find the specific directories consuming the most space. For this, we'll use a "du" command, short for "disc usage." Just something to keep in mind, even though we can see that the root file system is mostly full, we're focusing on the "/home" directory, the reason why is 'cause there was a file created in there as an example, so you can see how a file can take up space in a particular directory. All right, I'm going to clear my screen. All right, so the next step that we're going to do is to drill down and find the specific directory, which we already know is "/home," consuming the most space. For this, we use the "du" command, short for "disc usage," so we can use "du -ah /home/Instructor." From this, we can see that the "/home/file1.txt" file is consuming most of the space, so we would investigate further within it. Just to note, remember, "du -ah," "h" is for human-readable format, and "a" lists all the files in the directory because without the "-a," it would just list the directories in that file system. Lastly, we can use "du -ah |," and what this does, it will get all the output from the first command and push it to the next command, so we still have to put in the actual location that we are trying to query, so "/home/instructor," and then, "sort," this will sort all the output, we have "r," which is reverse, which means it'll reverse the order that it prints, "h" is for human-readable, and then, "head" will just print the first number of lines that I pick, that's what the "-n" stands for. In this case, it'll be the first 20 lines. Remember, this could be case-sensitive, so this can happen on occasion, just a quick note to know that Linux is case-sensitive. All right, once we do that, you can see the top 20 results of the actual directory, and in this case, we can see that "file1.txt" is taking up 200 megabytes, you can see this on the left side, and you can see this directory is taking 233 megabytes, as you can see, this file has taken up the most space in the directory. If we type in "rm file1.txt," this will remove the file, and if we run the command again, we can see now, it's gone, and this directory is only taking 33 megabytes, which is a huge difference. And this is just a quick look into how you can tackle disc utilization issues in the Linux command line.

Contents