Linux disk space directory

How to find out the free disk space for a given path on a linux shell? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

1) I am in some directory 2) I want to find out how much free space is left there Is there a simple command that does this? I don’t want to look in fstab or whatever, having to map the devices & mount points in my mind in order to determine how much free space I have left.

This question is not a dupe of 230407, since it is specific to home directory. As one answer mentions, there could be a quota imposed on each user’s home directory.

4 Answers 4

Better yet: df -h . or df -h path-to-file

df -h seems to work fine, but I can’t df -h . or df -h path-to-file to work. For all 3 of those commands on my Amazon server, my output just looks like: Filesystem Size Used Avail Use% Mounted on /dev/xvda1 30G 21G 8.7G 71% /

@D.Tate df returns the disk space usage. So it seems that you have only one partition (disk) on your server; namely /dev/xvda1. All your files are on this partition. So you get only the disk space usage of this partition for all files.

The ‘df’ command others discuss is only half the equation. Knowing the file system has free space does not imply that the user has access to the space.

You can also use the command:

To find out the free space on the current file system. ‘df’ is smart enough to walk the tree for you and report it. If you want to check quotas (see below) then you can process the output of df to find the file system to check the quota on.

There may be no free inodes (df -i $PWD), there could be reserved blocks for the super user (by default on ext2/3/4, 5% of the total is reserved for root). I believe df shows the free space including the reserved blocks, so the number you see is actually higher than is available if you’re not root.

The user may have quota restrictions. Quota restrictions is far less common these days since the cost of storage is so low, but it’s worth checking with the quota command too.

Читайте также:  Подключение планшета в linux

Источник

Find Out How Much Disk Space a Directory Consumed from the Command Line

On a graphical desktop environment, you can find out how much disk space a directory consumed by just right clicking on a directory and going to the Properties. It’s really simple.

From the command line, you can’t see how much disk space the directory is using that easily. But there are programs such as du and ncdu that you can use to find out the disk space a directory is consuming.

In this article, I will show you how to use du and ncdu to find out the disk space a directory or directories are consuming. So, let’s get started.

Using du to Find Directory Disk Usage:

The du command is available in all modern Linux distribution by default. You don’t have to installing anything extra.

The du command with the options -s (–summarize) and -h (–human-readable) can be used to find out how much disk space a directory is consuming.

For example, let’s say, you want to check how much disk space the ~/Downloads directory is consuming. To do that, run the du command as follows:

As you can see, the ~/Downloads directory consumed about 813 MB of disk space.

At times, you may need super user (root) privileges in order to check how much disk space certain directory is consuming. This is because, if you don’t have permission to read a file in a directory, then the du command can’t analyze it to find the disk space that file is using as well.

For example, let’s say, you want to calculate how much disk space the /etc directory is consuming. To do that, run the du command as follows:

As you can see, the /etc directory consumed only 13 MB of disk space.

With the du command, you can find out how much disk space each sub directories inside a directory consumed as well.

For example, if you want to know how much disk space each sub directories inside your login users HOME directory (~) consumed, then you can run the du command as follows:

As you can see, the size of each directory inside my login users HOME directory is listed. The last line also shows the total disk space consumed by the login users HOME directory.

Using ncdu to Find Directory Disk Usage:

ncdu is a ncurse based terminal disk usage analyzer. You can also call it a terminal version of graphical GNOME Disk Usage Analyzer (Baobab) app. It is a great tool for monitoring disk usage per directory basis on a headless server.

The ncdu software package is not installed by default on Ubuntu/Debian. But, it is available in the official package repository of Ubuntu/Debian. So, it is really easy to install.

First, update the APT package repository cache with the following command:

Then, install ncdu on your Ubuntu/Debian machine with the following command:

Now, you can start ncdu with the following command:

Or run as super user with the following command:

ncdu should start. It should look as shown in the screenshot below.

Читайте также:  Linux повышение привилегий sudo

By default, ncdu will show you the sub-directories of your current working directory. As you can see, it’s showing sub-directories of my login user’s HOME directory.

You can see how much disk space each directory consumed. There’s a nice looking graph there as well. It shows comparatively how much disk space is used by a particular directory. You can press the g key on your keyboard to toggle between graph, percentage, graph + percentage view if you want.

e symbol in a directory means the directory is empty.

You can see how much disk space the parent directory (in my case /home/shovon) is using in total and the number of files and directories (items) inside the parent directory here in the ncdu interface.

You can use the and arrow keys to navigate in the ncdu interface. You can also select a directory and press to see the contents of the directory as well.

If you want to exit out of the ncdu interface, press q.

You can manually tell ncdu to summarize a specific directory when you start ncdu.

For example, let’s say, you want to take a quick look into the /usr directory with ncdu. To do that, start ncdu as follows:

As you can see, the contents of the /usr directory is shown in the ncdu interface.

So, that’s how you find out how much disk space a directory consumed from the command line in Linux. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.

Источник

How to Get the Size of a Directory in Linux

Many users run Linux from the command line. However, the command line — sometimes known as the terminal — doesn’t have an intuitive interface for checking disk space in Linux.

This guide shows you how to find the size of a specific directory in Linux from the command line.

Tutorial on how to find directory size linux

  • A system running Linux
  • A command line / terminal window (available by clicking Search, then typing terminal)
  • A user account with sudo or root privileges

Note: In Linux, a directory is the equivalent of a folder in Windows. A directory may have directories inside (called subdirectories), or it may only contain files.

Option 1: Display the Size of a Directory Using the du Command

The du command stands for disk usage. This command is included by default in most Linux distributions.

You can display the size of your current directory by typing du in the command line:

The system should display a list of the contents of your home directory, with a number to the left. That number is the size of the object in kilobytes.

An example of the du command output.

You can add the -h option to make the output more readable:

Readable list of contents of your home directory.

Each entry will start with a number and a letter. The number is the amount of space used, and the letter (usually K, M, or G) indicates Kilobytes, Megabytes, or Gigabytes. For example:

400K – 400 kilobytes 7.3M – 7.3 megabytes 2.2G – 2.2 gigabytes

To find the size of a specific directory different from your current working directory. The du command allows you to specify a directory to examine:

Читайте также:  Calam arch linux installer

This displays the size of the contents of the /var directory. You may see some entries with an error, as in the image below.

Display the size of a specific directory.

This happens when your user account does not have permission to access a particular directory. Use the sudo or su command to get access privileges:

Note: Some versions of Linux don’t enable sudo by default. You can use the su command to switch to the root user account instead.

To display total disk usage of a particular directory, use the -c command:

Options can be combined. If you wanted to repeat the previous command in human-readable format, enter the following:

You can limit the scan to a certain level of subdirectory by using the max-depth option. For example, to scan only the size of the top directory, use —max-depth=0 :

If you wanted to list only the top directory and the first layer of subdirectories, change —max-depth=1 :

Find the size of the top directory

If you run into trouble or want to explore more options for the du command, enter the following command to display the help file:

Option 2: Get Size of Directory in Linux Using tree Command

By default, the tree command is not included in some versions of Linux. To install it, enter the following:

The tree command displays a visual representation of your directories. It uses lines to indicate which subdirectories belong where, and it uses colors to indicate directories and files.

tree can also be used with options. To display a human-readable size of the current directory’s subdirectories, enter the following:

Display disk usage using the tree command.

Like the du command, tree can target a specific directory:

This command takes a few moments since the /var directory has many entries.

The tree command also has a help file, which you can access by entering:

Option 3: Find the Size of a Linux Directory Using ncdu Command

The ncdu tool stands for NCurses Disk Usage. Like the tree command, it is not installed by default on some versions of Linux. To install it, enter the following:

The ncdu utility is an interactive display of your disk usage. For example, enter the following:

Display Disk Usage Using the ncdu command.

In the upper left corner, it displays the current directory being scanned. A column on the left displays the numerical size, a graph of #- signs to indicate the relative size, and the file or directory.

Use the up and down arrows to select different lines. The right arrow will browse into a directory, and the left arrow will take you back.

ncdu can be used to target a specific directory, for example:

For help, press the ? key inside the ncdu interface. To quit, press the letter q .

Note: Learn how to move directories in Linux using the GUI or system commands.

You now have three different options to find the size of a directory in Linux operating systems.

If you want to learn more about directories in Linux, read our article how to rename directories in Linux.

Источник

Оцените статью
Adblock
detector