The Linux command wc adopted by means of the -c flag (wc -c) can be utilized to rely report bytes.
This instructional explains find out how to rely report bytes the use of each wc and du instructions. After studying this instructional, you are going to know the way to simply rely bytes, strains, and phrases in Linux.
How to rely bytes in Linux the use of wc -c:
The syntax is lovely easy; the instance under presentations the wc -c command used to rely the bytes of the report named linuxhintsignal.c.
As you’ll be able to see within the output, the report has 106 bytes.
The command wc -c will also be used to rely more than one report bytes, as proven within the instance under during which bytes for linuxhintsignal.c and wp-downgrade.zip are counted.
wc -c linuxhintsignal.c wp-downgrade.zip
As you’ll be able to see, wc prints the bytes of every report and the overall sum.
You can even enforce the wildcard to rely all recordsdata inside a listing, as proven under.
Using the wildcard, wc will print all recordsdata and their bytes rely as proven above.
The wc command comes in handy for extra functions than counting bytes. This command may be helpful to rely strains, phrases, and characters inside a report or more than one recordsdata.
If you run wc with out flags, handiest adopted by means of the report title, it is going to print 3 columns as proven within the symbol under.
The first column (11) presentations the choice of strains. The 2nd column (14) presentations the phrase rely, and the 3rd column presentations bytes.
Of route, you can also rely every feature one at a time.
You want to upload the -l flag to rely the road quantity, as proven within the instance under.
As you’ll be able to see, the report comprises 11 strains.
The instance under presentations find out how to execute a wordcount the use of the wc command with the -w flag.
The following instance presentations find out how to enforce a pipe to mix instructions ls and wc to get the overall recordsdata to rely inside a listing.
You can learn all wc options by means of working:
You can even talk over with the net guy web page at https://linux.die.internet/guy/1/wc.
How to rely bytes in Linux the use of du:
The du command additionally can be utilized to rely bytes. By working the du command adopted by means of the -b flag and the report title, you’ll be able to get the bytes rely as proven within the following symbol.
As with the wc command, with the du command, you can also outline more than one recordsdata to be counted, as proven within the screenshot under. The distinction with the wc’s output is the du command gained’t display the overall sum.
du -b linuxhintsignal.c wp-downgrade.zip
As stated in the past, the variation with wc is the output doesn’t display the overall quantity of bytes. To get the overall sum the use of du, you wish to have so as to add the -c flag, as proven under.
du -bc linuxhintsignal.c wp-downgrade.zip
Now let’s say you don’t need the output in bytes however in a human-readable layout; for this, you’ll be able to enforce the -h (human) flag.
du -h linuxhintsignal.c wp-downgrade.zip
As you’ll be able to see, the output now’s human-friendly.
The command du can be utilized to print report sizes in any unit you wish to have. The instance under presentations find out how to print the scale in kilobytes the use of the -k flag.
du -k linuxhintsignal.c wp-downgrade.zip
It is essential to explain that the du command can’t give you the general quantity of kilobytes or megabytes if the report dimension doesn’t fit the precise unit; in this kind of case, the du command will go back the nearest worth of the unit layout you outlined.
Also, you’ll be able to print the scale of recordsdata in megabyte devices by means of the use of the -m flag, as proven under.
du -m take away.iso linuxhintsignal.c
As you’ll be able to see, you’ve the lead to megabytes, no longer the precise quantity of megabyte however the nearer to the true worth in bytes.
As you’ll be able to see, counting bytes the use of the wc -c command is lovely easy. Linux gives alternative ways to reach this activity; this instructional targeted at the 2 maximum commonplace instructions to rely recordsdata dimension in byte devices. As it’s worthwhile to see, there’s no significant distinction between wc and du instructions when counting bytes. The handiest distinction described on this instructional (moreover to flags) is the overall sum of bytes within the output. The wc command may be helpful to be carried out with pipes and different instructions appearing more information.
Thank you for studying this instructional at the wc command to rely bytes. Keep following us for extra Linux pointers and tutorials.