Awesome Linux Tools - ncdu, Scan your Hard Disk and free up Space!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome back to my awesome linux tools series the series where i show you guys an awesome tool or utility that i think is going to make a difference for you as a linux administrator or linux enthusiast in today's video we're going to go over the ncdu command the end curses disk usage tool and what this tool enables you to do is find out where all that hard drive space is going i mean no matter how big our hard drives get for some reason or another we just keep losing space files get larger and more plentiful and if you manage a file server then you especially know how tedious that can be when you have a bunch of people saving files in one server but the ncdu command is definitely one that i recommend that everyone installs and in today's video we're going to go through the ncdu command in all its glory so let's get started but first we do need to make sure that ncdu is installed and most of the time well it's not most distributions don't even include ncdu by default but it is one of those packages that i always make sure is installed because it's just so useful so let's see if i have it installed and i know i do because like i said i always make sure that ncdu is installed but in case it's not installed on your system then what i recommend you do is go ahead and install it basically you just use your package manager and install the ncdu package so in debian and ubuntu it's going to look something like this obviously i don't need to run this because i already have it but if you don't already have it on your end and you're running on debian ubuntu or a distribution based on one of those then this command will go ahead and install ncdu on your system once it's installed how do you use it well actually it's very very simple you type ncdu and then you type the path where you want the scan to start from so for example if you want to search the entire file system then you include a single forward slash just like that now it's going to take quite a while in my case because as you can see here it's actually scanning my truenast server because on my thelio i actually have that mounted so i'm going to break out of this and the reason for that is i would prefer it to not search my entire file server in this case i'm logged into my desktop so i'm actually only concerned with the files that are on this particular machine not anything that's mounted that's an external resource like my trunas server so how do i fix that well that's actually easy because all you do is you add dash x as an option and what dash x will do is tell ncdu to not scan anything that's mounted only worry about the local resources on the particular system that you're logged into so let's see how the command differs now so as you can see it's going through all of my files right here and now what we see here is a list of folders that are in the root file system on my desktop sorted by size and as you can see my home directory is quite large so that's going to be at the very top and then it's going to order the rest of the directories from highest down to lowest now one of the things that's really cool about this is that you can actually select a folder so for example if i press enter on home obviously my user is going to be the one that's going to be the largest i'll just press enter on that and as you can see here my steam directory is going to be one of the larger files because that's where all my games are downloaded i have 299 gibby bytes of games as you can see here and i'm kind of curious which game is taking up the most storage let's find out so i'll just navigate through the folders here and as you can see here doom eternal clocks in at 79 gibby bytes so that's easily the biggest game that i have installed at this time now what i'm going to do is press q to quit out of ncdu and go back to the command line and i want to start over because there is a very important aside that i want to make sure you guys are aware of and it might actually go without saying but i just want to make sure you guys are aware of this the ncdu command only has access to scan directories that the user has access to so this is the example that i ran right here i didn't use sudo i'm logged in as myself currently so ncdu might not be showing me accurate information i mean i don't doubt for a minute that my home directory is going to be the largest of any of the directories here but it's not going to search through any of the directories that root owns or is owned by another user so for that we might want to consider using sudo the trade-off though is that if we do use sudo then we have full access to everything which is great however ncdu also facilitates the deletion of files and folders as well so when we run it with sudo we definitely want to be very careful so run it again and we're going to see the same results for the most part because i am the primary user on this system but imagine if this was a server for example that had multiple users that logged in then if you ran ncdu without sudo then your results might be especially skewed but anyway let's move on so i'm going to go into the var directory and then log and then as you can see here we have several different files now what i want to do is delete this file right here i don't need this old xor log anymore and it's only kbytes but let's just assume that this is a ginormous file and we need to get rid of it because we are running out of disk space so how exactly do we do that well what we could do is press d for delete and then it'll ask you if you're sure that you do indeed want to delete the particular item that you've highlighted so i'll go over to yes and i'll press enter and that's very useful because you can use ncdu to not only see which folders on your system are the biggest when it comes to file sizes you can also delete things as well and that's really great because if you are running this on a server especially a file server then you're probably going to want to use ncdu every now and then and keep an eye on the storage so next i'm going to quit out of ncdu yet again and let's just see which file systems i have mounted on this desktop so as you can see i have a few here i have a video cache directory that i use for editing that's what my editor uses for all of the optimized media proxy media and things like that so that's going to be a decent size at 199 gigabytes and of course we have the root file system but what if i just want to scan this particular mount right here well that's easy because we're using this variation of ncdu right here where we're scanning the entire root file system but you don't have to start from the root file system you can actually give it a directory to start from and what i'm going to do is remove the dash x because this is actually a mounted device it's actually a pcie storage device anyway i'll press enter and right here we can see some information about the cache and these files are probably not going to make all that much sense because these are created by the video editor and we have a what looks like a random or hashed name right here so we're not going to know which is which but anyway the point is you can start from any directory even a mounted directory and in that case you might not even need to use sudo because well i probably didn't need to use sudo i am the owner of this particular mount so if i was to go ahead and remove sudo from this command right here it shouldn't change anything at all as you can see i get the same results now the most important tip that i'll give you guys regarding ncdu is to make sure that it's installed now i know that seems like a very obvious thing but think about it like this you definitely don't want to wait until your storage is full because in that case well you can't install ncdu because you have no space to install it in so definitely make sure that ncdu is among the packages that you install by default on your linux servers because it might just come in handy like i mentioned earlier ncdu is one of those tools that i like to make sure is installed in every single linux installation within my jurisdiction it's that useful and also make sure that you have it installed before storage becomes a problem because you certainly can't install adapter if your disk is completely full now of course i hope you never need ncdu because you have so much storage that you'll never run out or you're just that good at managing storage but sometimes all it takes is that one user that saves a ginormous file somewhere they're not supposed to and then you have to go in and find out what they did and then cdu is just a great way to do that so hopefully this video helped you out and if it did please click that like button that lets youtube know that people need to see more linux content just like this i'd really appreciate that and i'll see you again in the next video thanks for watching [Music] you
Info
Channel: Learn Linux TV
Views: 23,621
Rating: undefined out of 5
Keywords: Linux, Tutorial, Howto, Guide, Learn Linux, open-source, open source, gnu/linux, LearnLinuxTV, ncdu, disk usage, storage, storage full, disk full, check disk, boabab, scan hard drive, linux tools, awesome linux tools, utilities, linux utilities, devops, command line, linux tutorial, free disk space linux, free up disk space, clean up, free disk space, arch linux, du command, linux tutorial ubuntu, linux tutorial 2022, command line linux, command line basics, command line tools
Id: nj8HtCNYOsU
Channel Id: undefined
Length: 9min 30sec (570 seconds)
Published: Thu Mar 24 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.