What is using all my disk space linux

No more disk space: How can I find what is taking up the space?

I’ve run into a problem on one of my servers running 16.04: there is no disk space left. I have no idea what is taking up the space. Is there a command to list the current directory sizes, so I can traverse and end up in the directory taking up all the space?

Darn you, now I went looking, found this bugs.launchpad.net/ubuntu/+source/baobab/+bug/942255 and wish it was a thing.

wrt «no GUI, is a server»: you could install the GUI app (assuming you are happy with it and the support libraries being on a server) and use is on your local screen via X11-tunnelled-through-SSH with something like export DISPLAY=:0.0; ssh -Y @ filelight (replace filelight with your preferred tool). Of course with absolutely no space left, if you don’t already have the tool installed you’ll need to use something else anyway!

13 Answers 13

As always in Linux, there’s more than one way to get the job done. However, if you need to do it from CLI, this is my preferred method:

I start by running this as root or with sudo:

du -cha --max-depth=1 / | grep -E "M|G" 

The grep is to limit the returning lines to those which return with values in the Megabyte or Gigabyte range. If your disks are big enough, you could add |T as well to include Terabyte amounts. You may get some errors on /proc , /sys , and/or /dev since they are not real files on disk. However, it should still provide valid output for the rest of the directories in root. After you find the biggest ones you can then run the command inside of that directory in order to narrow your way down the culprit. So for example, if /var was the biggest you could do it like this next:

du -cha --max-depth=1 /var | grep -E "M|G" 

That should lead you to the problem children!

Additional Considerations

While the above command will certainly do the trick, I had some constructive criticism in the comments below that pointed out some things you could also include.

  1. The grep I provided could result in the occasional «K» value being returned if the name of the directory or file has a capital G or M. If you absolutely don’t want any of the K valued directories showing up you’d want to up your regex game to be more creative and complex. e.g. grep -E «^[0-9\.]*[MG]»
  2. If you know which drive is the issue and it has other mounted drives on top of it that you don’t want to waste time including in your search, you could add the -x flag to your du command. Man page description of that flag:
 -x, --one-file-system skip directories on different file systems 

Your grep returns any folders with the letters M or G in their names too, a creative regex should hit numbers with an optional dot+M|G, maybe «^5*[.]*9*[MG]»

If you know it’s one drive that’s the issue, you can use the -x option to make du stay on that one drive (provided on the command-line). You can also pipe through sort -h to correctly sort the megabyte/gigabyte human-readable values. I would usually leave off the —max-depth option and just search the entire drive this way, sorting appropriately to get the biggest things at the bottom.

@alexis My experience is that I sometimes end up with other rubbish mounted below the mountpoint in which I’m interested (especially if that is / ), and using -x gives me a guarantee I won’t be miscounting things. If your / is full and you have a separately-mounted /home or whatever, using -x is pretty much a necessity to get rid of the irrelevant stuff. So I find it’s just easier to use it all the time, just in case.

You can use ncdu for this. It works very well.

enter image description here

I’m kicking myself as I actually normally use this program, however since there is no space left I can’t install it haha

@KarlMorrison i see several possible solutions, just mount it over sshfs on another computer and run ncdu there (assuming you already have an ssh server on it..) — or if you don’t have an ssh server on it, you can do the reverse, install ncdu on another server and mount that with sshfs and run ncdu from the mount (assuming you already have sshfs on the server) — or if you don’t have either, . if ncdu is a single script, you can just curl http://path/to/ncdu | sh , and it will run in an in-memory IO stdin cache, but that’ll require some luck. there’s probably a way to make a ram-disk too

once installed type sudo ncdu / from the command line. sudo because if you dont put sudo, it wont report sizes for folders owned by root, and / because if you dont type that it will only report recusively down from the folder you’re in

sudo du -aBM -d 1 . | sort -nr | head -20 

Occasionally, I need to run it from the / directory, as I’ve placed something in an odd location.

I often find it more useful to do this without the -d 1 switch (and usually with less instead of head -20 ), so that I get a complete recursively enumerated list of all files and directories sorted by the space they consume. That way, if I see a directory taking up a lot of space, I can just scroll down to see if most of the space is actually taken up by some specific file or subdirectory in it. It’s a good way to find some unneeded files and directories to delete to free some space: just scroll down until you see something you’re sure you don’t want to keep, delete it and repeat.

@KarlMorrison it doesn’t read it quicker, it’s just that sort waits for the output to be completed before beginning output.

@muru Ah alright. I however get information quicker so that I can begin traversing quicker if that’s a better term!

In case you are also interested in not using a command, here’s an app: Filelight

It lets you quickly visualize what’s using disk space in any folder.

enter image description here

@KarlMorrison I think there are ways to run GUI programs over ssh, but that’s an idea for later when you’ve got space to install packages

@David Oh yeah, I’m trying to get out of that. It used to be necessary on another platform that I used. I’ll fix that comment.

@Karl yes, it’s easy if X is already installed on the client: ssh -X and then run your program from the command line

@MarkYisri the point is that you need to install the program and its dependencies. And the case of Filelight requires at least KDElibs and Qt, which are not really small. See e.g. this page for filelight Ubuntu package, note how many dependencies it has.

There are already many good answers about ways to find which directories take most of the space. If you have reason to believe that a few large files are the main problem, rather than many small ones, you could use something like:

I don’t know Ubuntu and can’t check my answer but post here my answer based on my experience as unix admin long time ago.

    Find out which filesystem runs out of space

But what happened if the du output is not approximately the available space displayed by df?

If the du output is larger then you have missed a subdirectory where another filesystem is mounted. If the du output is much smaller, then som files are not shown in any directory tha du inspects. There can be different reasons for his phenomena.

  1. some processes are using a file that was already deleted. Therefore this files were removed from the directory and du can’t see them. But for the filesystem their blocks are still in use until the proceses close the files. You can try to find out the relevant processes (e.g. with lsof) and force them to close this files (e.g by stopping the application or by killing the processes). Or you simply reboot your machine.
  2. there are files in directories that aren’t visible anymore because on one of their parent directories another filesystem is mounted. So if you have a file /myfilesysem/subdir/bigfile and now mount another filesystem on /myfilesystem/subdir then you cannot see this file anymore and

will report a value that does not contain the size of /myfilesystem/subdir/bigfile. The only way to find out if such files exist is to unmount /myfilesystem/subir and check with

Besides this systematic way using the du command there are some other you can use. So you can use the find command to find files that are larger then some value you supply, you can search for files that larger than some value you supply or that were newly created or have a special name (e.g. *.log, core, *.trc). But you always should do a df as described in 1 so that you work on the right filesystem

Источник

5 Linux commands to check free disk space

How to find files in Linux

Keeping track of disk utilization information is on system administrators’ (and others’) daily to-do list. Linux has a few built-in utilities that help provide that information.

Linux df command

The df command stands for «disk-free,» and shows available and used disk space on the Linux system.

df -h shows disk space in human-readable format

df -a shows the file system’s complete disk usage even if the Available field is 0

df command

df -T shows the disk usage along with each block’s filesystem type (e.g., xfs, ext2, ext3, btrfs, etc.)

df -i shows used and free inodes

df command

You can get this information in a graphical view using the Disks (gnome-disk-utility) in the GNOME desktop. Launch it to see all disks detected by your computer, and click a partition to see details about it, including space used and space remaining.

GNOME Disks

Linux du command

du shows the disk usage of files, folders, etc. in the default kilobyte size

du -h shows disk usage in human-readable format for all directories and subdirectories

du -a shows disk usage for all files

du -s provides total disk space used by a particular file or directory

du command

The following commands will check your total space and your utilized space.

This information can be represented visually in GNOME with the Disk Usage application, or with Filelight in the KDE Plasma desktop. In both applications, disk usage is mapped to concentric circles, with the middle being the base folder (usually your /home directory, but it’s up to you) with each outer ring representing one directory level deeper. Roll your mouse over any segment for detailed information about what’s taking up space.

Disk usage

Linux ls -al command

ls -al lists the entire contents, along with their size, of a particular directory

ls -al command

Linux stat command

stat displays the size and other stats of a file/directory or a filesystem.

stat command

Linux fdisk -l command

fdisk -l shows disk size along with disk partitioning information

fdisk - l command

These are most of the built-in utilities for checking file space in Linux. There are many similar tools, like Disks (GUI), Ncdu, etc., that also show disk space utilization. Do you have a favorite tool that’s not on this list? Please share in the comments.

This article was originally published in July 2018 and has been updated to include additional information.

Check disk usage

Check used disk space on Linux with du

Find out how much disk space you’re using with the Linux du command.

Free disk space

Use df to check free disk space on Linux

Find out how much Linux disk space you have left with the df command.

Источник

How to determine what process is eating up all available disk space?

Suddenly all the available disk space on / has disappeared. If I make room in the disk (by deleting ~50GB of stuff, for example), after a few minutes I am back to 0 available disk space (according to df ). Clearly, some process is eating up disk space at a rapid rate, but I can’t figure out what it is. One thing is certain, though: whatever it is, it must be creating many small files, because there are no files bigger than 10GB on the disk, and all the ones bigger than 1GB are much older than today. How can I find what’s eating up disk space? FWIW, only df sees the problem, not du . For example, below I show several «snapshots» from du and df taken 60s. apart. (I did this after I had made some room in the disk.) Notice how du ‘s output remains steady (at 495G ), but df shows a steadily shrinking amount of available space. (I’ve followed the recommendation given here. IOW, /mnt/root is pointing to / .)

# while true; do du -sh /mnt/root && df -h /mnt/root; sleep 60; done 495G /mnt/root Filesystem Size Used Avail Use% Mounted on /dev/sdb1 880G 824G 12G 99% /mnt/root 495G /mnt/root Filesystem Size Used Avail Use% Mounted on /dev/sdb1 880G 825G 11G 99% /mnt/root 495G /mnt/root Filesystem Size Used Avail Use% Mounted on /dev/sdb1 880G 827G 8.9G 99% /mnt/root 495G /mnt/root Filesystem Size Used Avail Use% Mounted on /dev/sdb1 880G 827G 8.1G 100% /mnt/root 495G /mnt/root Filesystem Size Used Avail Use% Mounted on /dev/sdb1 880G 828G 7.5G 100% /mnt/root 

You dealing with a deleted file, that is why du does not register it. The /var size, if syslog is the culprit, wont register it too.

Источник

Читайте также:  Linux bin to header
Оцените статью
Adblock
detector