1

The question says Remove the entire git directory (it is not used in our tutorials). Now repeat the above calculation for disk space, but this time give the answer in blocks. I successfully deleted the git directory but now I need to find the disk space in blocks I've done df -k and this came up:

Filesystem                  1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos_lvm-root   6813696 4533956   2279740  67% /
devtmpfs                       234236       0    234236   0% /dev
tmpfs                          250168      84    250084   1% /dev/shm
tmpfs                          250168    4792    245376   2% /run
tmpfs                          250168       0    250168   0% /sys/fs/cgroup
/dev/sda1                      508588  209632    298956  42% /boot
tmpfs                           50036      16     50020   1% /run/user/42
tmpfs                           50036       0     50036   0% /run/user/0

What do I need to do?

  • Hi, @Hunter12345 What is the path from which you deleted the git directory ? – sai sasanka Oct 10 '18 at 10:26
  • Hey, @saisasanka I've deleted the git directory in /usr/share/doc – Rakata Infinite Empire Oct 10 '18 at 10:33
0

Try this,

Lets say you deleted the directory git from the path /usr/share/doc. Now run df -k / provided usr/share/doc is present on / partition.It might give you something like this:

    Filesystem                  1K-blocks    Used   Available Use%  Mounted on
/dev/mapper/centos_lvm-root   6813696      4533956   2279740  67%    /

Here 6813696 is the total number of blocks available out of which 2279740 are free. Each block size is of 1024 bytes.

Now your homework answer would be 2279740 blocks.

You can always run df -kh to see the disk space utilization in human readable terms like 1GB etc

But if you want block size to be 512 or somethng else, try this:

df --block-size=512 /

df --block-size=<your_block_size> <your_partition>

EDIT: To get the size in Mega bytes try this:

df -hm /

The number under Available would be your answer.

Assuming its 2279740 blocks each of 1024 byte size are free, the answer in Ms would be 2226.30859375M

Calculation : 2279740/1024 or

In bytes 2279740*1024 = 2334453760 bytes;

In KB: 2334453760/1024=2279740KB ;

In MB 2279740/1024=2226.30859375M ;

In G 2226.30859375/1024=2.174129486083984G

For more options of df , try man df or df --help

  • Sorry it's telling me to give it in Ms (eg 112M) – Rakata Infinite Empire Oct 10 '18 at 10:54
  • @Hunter12345, added it to the answer. – sai sasanka Oct 10 '18 at 10:58
  • @saisasnka Okay for some odd reason I'm getting a fail for that part I just don't even know what it's asking me. It says Question 14: How much space is available? Remove the entire git directory (it is not used in our tutorials). Now repeat the above calculation for disk space, but this time give the answer in blocks. Which the above answer says In human readable form (eg 123M) how much disk space is available on the main filesystem? – Rakata Infinite Empire Oct 10 '18 at 14:58
  • @Hunter12345 If you want the space in blocks, in the answer its explained with df -k . If you want space in human readable format , its explained in the form of df -h or df -hm . If you want space in blocks , provided a block size , the answer is explained in the form of df -B.Now what are you getting fail for ? – sai sasanka Oct 11 '18 at 5:42
0

Blocks traditionally had a size of 512 bytes (they had a strong correlation with disk sectors). You can tell df what block size, or unit, to use. From the POSIX df specification:

The format of the default output from df is unspecified, but all space figures are reported in 512-byte units, unless the -k option is specified.

Assuming your homework question assumes blocks are 512 bytes, just remove the -k. If df still uses 1k blocks, you might have the BLOCKSIZE variable set to K. Unset it with unset BLOCKSIZE and set POSIXLY_CORRECT=yes.

You can reduce the output to just include the relevant file system with

df .     # or maybe df /usr/share/doc

(assuming your current working directory is on the relevant file system).

  • Okay, I got this now. Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/centos_lvm-root 6813696 4534480 2279216 67% / – Rakata Infinite Empire Oct 10 '18 at 10:44
  • But it's telling me to give the answer in blocks. – Rakata Infinite Empire Oct 10 '18 at 10:45
  • @Hunter12345 Does using df --block-size=512 work? If all else fails, read the docs: man df. – Jens Oct 10 '18 at 11:31
  • @Hunter12345 To get the POSIX-mandated output (512 byte blocks) you need to set the POSIXLY_CORRECT=yes variable. – Jens Oct 10 '18 at 12:19
  • I think the question wants a df -B? to find the block but I don't know how to do that??? – Rakata Infinite Empire Oct 10 '18 at 15:13
0

You can try something like this:

#!/bin/bash

TO_REMOVE="/usr/share/doc/git"
BASE_DIR=$(dirname $TO_REMOVE)

SIZE_BEFORE=$(df $BASE_DIR | tr -s ' ' | cut -d" " -f 3 | tail -1)
rm -Rf $TO_REMOVE
SIZE_AFTER=$(df $BASE_DIR | tr -s ' ' | cut -d" " -f 3 | tail -1)

echo $(($SIZE_BEFORE - $SIZE_AFTER))

dirname - strips the last component of path

tr -s ' ' - squashes all spaces

cut -d" " -f 3 - selects second column

tail -1 - selects last row from column

  • 2
    Just saying, the OP doesn't want to delete /usr/share/doc – sai sasanka Oct 10 '18 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.