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 command, y'all obtain both the actual deejay usage and the truthful 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 space 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 cake is still allocated to it because the file organisation doesn't have a smaller unit of existent estate to use.

Unless a file's size is an exact multiple of blocks, the infinite it uses on the hard drive must e'er be rounded up to the next whole block. For example, if a file is larger than two blocks simply smaller than three, information technology still takes three blocks of space to store information technology.

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 brand up the file. The second is the effective size of the file on the hd. This is the number of file system blocks necessary to store that file.

An Example

Let'south await at a simple example. We'll redirect a unmarried character into a file to create a pocket-size file:

echo "1" > geek.txt

Now, nosotros'll use 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 ii bytes. Why is information technology two bytes when we only sent i character to the file? Let's take a await at what's happening inside the file.

We'll utilize the hexdump command, which volition give us an exact byte count and let us to "see" non-printing characters as hexadecimal values. Nosotros'll too use the -C (approved) option to forcefulness the output to show hexadecimal values in the body of the output, likewise as their alphanumeric graphic symbol equivalents:

hexdump -C geek.txt

The output shows united states of america that, beginning at offset 00000000 in the file, there'due south a byte that contains a hexadecimal value of 31, and a ane 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 stand for the digit one. The hexadecimal value of 0A is used to represent the Line Feed character, which cannot be shown equally an alphanumeric character, so it's shown equally a period (.) instead. The Line Feed character is added by repeat . By default,echostarts a new line after information technology displays the text it needs to write to the concluding window.

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

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

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

du geek.txt

Information technology says the size is iv, simply four of what?

At that place Are Blocks, and So At that place Are Blocks

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

Showtime, it checks the post-obit environs variables:

  • DU_BLOCK_SIZE
  • BLOCK_SIZE
  • BLOCKSIZE

If whatsoever of these exist, the block size is set, and du stops checking. If none are ready,du defaults to a block size of 1,024 bytes. Unless, that is, an environment variable chosen POSIXLY_CORRECT is fix. If that's the case, du defaults to a cake size of 512 bytes.

So, how do nosotros find out which one is in use? You can check each environment variable to work it out, but there's a quicker way. Let's compare the results to the block size the file system uses instead.

To discover the block size the file arrangement uses, we'll use the tune2fs program. We'll then use the -l (list superblock) option, pipage the output through grep, and then print lines that contain the discussion "Cake."

In this example, we'll look at the file system on the first partitioning of the beginning hard drive, sda1, and nosotros'll demand to use sudo:

sudo tune2fs -l /dev/sda1 | grep Block

The file organization cake size is 4,096 bytes. If we split that by the result we got from du (four), it shows thedu default block size is i,024 bytes. We now know several of import things.

First, we know the smallest corporeality of file system existent estate that can be devoted to storing a file is iv,096 bytes. This ways even our tiny, 2-byte file is taking up four KB of hard bulldoze infinite.

The second matter to keep in mind is applications dedicated to reporting on hard drive and file arrangement statistics, such as du, ls, andtune2fs, can have different notions of what "block" means. The tune2fs application reports true file system block sizes, whilels and du tin be configured or forced to utilise other block sizes. Those cake sizes are not intended to chronicle to the file system block size; they're just "chunks" those commands use in their output.

Finally, other than using different block sizes, the answers from du and tune2fs convey the aforementioned meaning. The tune2fs result was 1 block of 4,096 bytes, and the du issue was four blocks of ane,024 bytes.

Using du

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

Permit's take a look at an example:

du

The size is reported in the default block size of 1,024 bytes per block. The unabridged subdirectory tree is traversed.

Using du on a Different Directory

If you desiredu to report on a different directory than the current ane, you lot tin pass the path to the directory on the command line:

du ~/.cach/evolution/

Using du on a Specific File

If you wantdu to written report on a specific file, laissez passer the path to that file on the command line. You can also pass a beat blueprint to a select a grouping of files, such every bit *.txt:

du ~/.bash_aliases

Reporting on Files in Directories

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

du -a

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

Limiting Directory Tree Depth

Y'all tin can tell du to list the directory tree to a certain depth. To do 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, only they're not all listed. To set a maximum directory depth of one level, use this command:

du -d 1

The output lists the total size of that subdirectory in the electric current directory and also provides a total for each 1.

To list directories one level deeper, apply this command:

du -d ii

Setting the Block Size

You lot can use the block pick to set a block size for du for the current operation. To use a cake size of one byte, use the following command to get the exact sizes of the directories and files:

du --block=1

If you want to utilise a block size of one megabyte, y'all can use the -m (megabyte) option, which is the aforementioned as --block=1M:

du -thousand

If you lot want the sizes reported in the nigh appropriate block size according to the disk space used past the directories and files, use the -h (human-readable) option:

du -h

To come across the credible size of the file rather than the corporeality of difficult drive space used to store the file, apply the --apparent-size option:

du --apparent-size

You can combine this with the -a (all) choice to run across the credible size of each file:

du --apparent-size -a

Each file is listed, forth with its credible size.

Displaying Just Totals

If you wantdu to written report only the total for the directory, apply the -south (summarize) choice. Y'all tin also combine this with other options, such equally the -h (human being-readable) option:

du -h -s

Here, we'll use it with the --credible-size pick:

du --apparent-size -southward

Displaying Modification Times

To see the creation or last modification time and date, use the --fourth dimension option:

du --time -d ii

Strange Results?

If you come across strange results from du , especially when you cantankerous-reference sizes to the output from other commands, it's commonly due to the different block sizes to which different commands can be set or those to which they default. It could likewise be due to the differences between real file sizes and the disk space required to store them.

If you lot need to lucifer the output of other commands, experiment with the --block 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: prindlelareltat.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