banner



What Is The Size Of The Rc.conf File In Bytes

A Linux terminal window on an Ubuntu-style laptop.
Fatmawati Achmad Zaenuri/Shutterstock

When you apply the Linux du control, you obtain both the actual disk usage and the true size of a file or directory. We'll explain why these values aren't the same.

Actual Disk Usage and True Size

The size of a file and the infinite it occupies on your hard drive are rarely the same. Disk space is allocated in blocks. If a file is smaller than a block, an entire block is still allocated to information technology because the file system doesn't accept a smaller unit of measurement of real estate to use.

Unless a file's size is an verbal multiple of blocks, the space it uses on the hard bulldoze must e'er exist rounded up to the side by side whole block. For example, if a file is larger than two blocks simply smaller than three, it still takes three blocks of space to store it.

Two measurements are used in relation to file size. The first is the actual size of the file, which is the number of bytes of content that make upward the file. The second is the effective size of the file on the difficult disk. This is the number of file system blocks necessary to store that file.

An Example

Let'due south look at a simple instance. We'll redirect a single character into a file to create a small file:

echo "i" > geek.txt

Now, we'll apply the long format listing,ls, to await at the file length:

ls -fifty geek.txt

The length is the numeric value that follows the dave dave  entries, which is two bytes. Why is it two bytes when we only sent one grapheme to the file? Let's take a look at what'due south happening within the file.

We'll use the hexdump control, which will give us an verbal byte count and let the states to "see" not-printing characters every bit hexadecimal values. We'll as well use the -C (approved) selection to force the output to bear witness hexadecimal values in the body of the output, as well as their alphanumeric character equivalents:

hexdump -C geek.txt

The output shows us that, beginning at offset 00000000 in the file, there'due south a byte that contains a hexadecimal value of 31, and a one that contains a hexadecimal value of 0A. The right-hand portion of the output depicts these values as alphanumeric characters, wherever possible.

The hexadecimal value of 31 is used to represent the digit one. The hexadecimal value of 0A is used to represent the Line Feed character, which cannot exist shown equally an alphanumeric character, so it's shown as a period (.) instead. The Line Feed graphic symbol is added past echo . By default,echostarts a new line after it displays the text information technology needs to write to the last window.

That tallies with the output fromls and agrees with the file length of two bytes.

RELATED: How to Use the ls Control to List Files and Directories on Linux

Now, we'll use the du command to expect at the file size:

du geek.txt

Information technology says the size is four, but four of what?

At that place Are Blocks, and So There Are Blocks

When du reports file sizes in blocks, the size it uses depends on several factors. You can specify which block size it should use on the command line. If you don't force du to use a particular block size, it follows a set up of rules to make up one's mind which one to utilise.

First, information technology checks the following environment variables:

  • DU_BLOCK_SIZE
  • BLOCK_SIZE
  • BLOCKSIZE

If whatever of these exist, the cake size is set up, and du stops checking. If none are set up,du defaults to a block size of 1,024 bytes. Unless, that is, an environment variable called POSIXLY_CORRECT is set. If that'south the instance, du defaults to a block size of 512 bytes.

So, how do we observe out which one is in utilise? You lot tin can bank check each environment variable to work information technology out, but there'southward a quicker way. Let's compare the results to the block size the file organization uses instead.

To discover the block size the file system uses, we'll use the tune2fs plan. We'll then use the -l (list superblock) option, pipe the output through grep, and and so print lines that contain the word "Block."

In this example, we'll expect at the file system on the first partition of the start difficult drive, sda1, and we'll demand to use sudo:

sudo tune2fs -50 /dev/sda1 | grep Block

The file system block size is four,096 bytes. If we divide that by the outcome we got from du (four), it shows thedu default block size is 1,024 bytes. We now know several important things.

First, we know the smallest amount of file organisation real estate that tin be devoted to storing a file is iv,096 bytes. This ways even our tiny, two-byte file is taking up 4 KB of difficult drive space.

The 2d thing to keep in mind is applications dedicated to reporting on hard drive and file organization statistics, such equally du, ls, andtune2fs, can accept different notions of what "block" ways. The tune2fs application reports truthful file arrangement block sizes, whilels and du can exist configured or forced to employ other block sizes. Those block sizes are non intended to relate to the file system block size; they're only "chunks" those commands use in their output.

Finally, other than using different block sizes, the answers from du and tune2fs convey the same significant. The tune2fs issue was one block of four,096 bytes, and the du result was four blocks of 1,024 bytes.

Using du

With no control line parameters or options, du lists the full disk space the current directory and all subdirectories are using.

Let's take a look at an example:

du

The size is reported in the default cake size of ane,024 bytes per block. The entire subdirectory tree is traversed.

Using du on a Different Directory

If you wantdu to report on a dissimilar directory than the electric current one, y'all can laissez passer the path to the directory on the command line:

du ~/.cach/development/

Using du on a Specific File

If y'all wantdu to report on a specific file, pass the path to that file on the command line. You tin can also pass a beat out design to a select a group of files, such every bit *.txt:

du ~/.bash_aliases

Reporting on Files in Directories

To have du report on the files in the electric current directory and subdirectories, use the -a (all files) option:

du -a

For each directory, the size of each file is reported, as well equally a total for each directory.

Limiting Directory Tree Depth

Y'all can tell du to listing the directory tree to a certain depth. To practise so, use the -d (max depth) option and provide a depth value equally a parameter. Note that all subdirectories are scanned and used to calculate the reported totals, but they're not all listed. To set a maximum directory depth of 1 level, utilise this command:

du -d one

The output lists the total size of that subdirectory in the current directory and too provides a total for each one.

To list directories 1 level deeper, utilize this command:

du -d 2

Setting the Block Size

You tin use the cake option to set a cake size for du for the electric current operation. To use a block size of one byte, utilize the following control to get the exact sizes of the directories and files:

du --block=1

If yous want to use a block size of one megabyte, you can use the -thou (megabyte) selection, which is the aforementioned equally --block=1M:

du -m

If you desire the sizes reported in the most advisable block size according to the deejay space used by the directories and files, use the -h (human-readable) option:

du -h

To see the credible size of the file rather than the amount of hard drive infinite used to store the file, utilise the --apparent-size option:

du --apparent-size

You can combine this with the -a (all) selection to see the apparent size of each file:

du --apparent-size -a

Each file is listed, along with its apparent size.

Displaying Only Totals

If y'all wantdu to report only the full for the directory, use the -s (summarize) option. You lot tin can also combine this with other options, such equally the -h (homo-readable) option:

du -h -s

Here, we'll employ it with the --apparent-size option:

du --credible-size -s

Displaying Modification Times

To run into the creation or last modification time and appointment, use the --time option:

du --time -d 2

Strange Results?

If you see foreign results from du , especially when you cross-reference sizes to the output from other commands, it's normally due to the different block sizes to which dissimilar commands can be prepare or those to which they default. It could also exist due to the differences between real file sizes and the deejay space required to store them.

If you need to match the output of other commands, experiment with the --cake option in du.

What Is The Size Of The Rc.conf File In Bytes,

Source: https://www.howtogeek.com/450366/how-to-get-the-size-of-a-file-or-directory-in-linux/

Posted by: morrissaileforseen.blogspot.com

0 Response to "What Is The Size Of The Rc.conf File In Bytes"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel