Let's look at truncating file size, using the command truncate.
Now the links truncate command is often used to shrink or extend the size of a file to a specified size.
Now, remember, one thing truncate is not the same command as if you wanted to compress a file or GS
Aberfoyle, which will reduce or shrink the size of a file.
TRUNCATE, on the other hand, will actually chop the file into the specified size.
So if your file size is, let's say, a hundred bytes and you use the command truncate and shrink it
down to 50, then it will actually chop the file and you will lose the data or the content of a file.
And whenever you if you Dukat to the file, you will see half of your data is gone.
If you are chopping, using the command truncate so the command that you will need to use to run it,
it's truncate minus as as first size, which is the option 10 is the actual integer to the specified
file, whichever file that you truncate to.
So this is the size option is everything is there.
So now let's go into our Linux machine and we will try Arcam in the truncate command or their.
OK, so we are in our Lennix machine to practice our truncate command or to go over it.
I will create a file call.
By the way, I am in my home directory and I am logged in as myself.
And my host name is my Linux machine, of course.
OK, and now I want you to create a file.
Touch and call it signed, filled.
Words.
The file is created, you could verify by doing less minus L and the name of the file and it enter,
you will see the file is there.
It has zero bytes and is owned by me and the permission, all that stuff.
Now do echo.
And type up the famous characters offside, sorry, the famous words that you could think of that of
Seinfeld, but if you don't know, then just follow my lead and just keep typing like the first word
is perfect.
Second word is giddyap, third word is yada, yada, um, kaberuka.
Serenity now and last one, let's say Festivus and put that to our Seinfeld file, so let's make it
a little bigger so you see all in one line.
So I'm actually acting out these words and I am putting it to the file name the file that you just created
hit enter.
Now go ahead.
And Dukat on Seinfeld words and you will see all of these words inside of that file.
Now do ls minus L and do Seinfeld and you will see the size of the file is now 57.
Now if you wanted to shrink that file using the command truncate then you would have to use.
Command truncate.
Minus s as an option.
Space the size that you wanted to specify.
And you wanted to shrink it, too, so right now it's 57, now let's make it 40 and the name of the
files and hit enter now do ls minus L to sign fell again and you will see the size has been reduced
to 40 bytes.
Now let's see the contents of the file now.
Sinovel words.
OK, you see the content right now when it did cat, it says puffy shirt, giddy up, yada, yada.
Kaberuka and ACR eat up to here.
That's it.
It did not complete the entire word serenity.
Now, see right here, as I have right here through every now and then, it actually removed Festivus
as well.
So it actually when I do cat again, Seinfeld, you see right here, it actually removed the last few
letters.
Why?
Because it has to chop it down.
Why?
He was used to truncate command if I wanted to chop the file.
Now remember, truncate command does not is not used to actually compress or make it size, make it
smaller while keeping the same content to be very careful.
Anyway, so this is the lesson where I wanted to Koha, that truncate command.
You could use this or you could also use that trunked to extend or make the file bigger.
So if I do truncate the hit up Parakey and I put it back to let's say 60 and hit enter and now do less
minus L Sinovel, you see the size is 60 now.
Does it mean that we are going to get our whole word serenity now and Festivus back in that file.
No, let's check, let's verify Dukat Steinfels words.
And you see it's not there.
It's still giving me the only the size.
That has all those words because it does not have the information, whatever, that we've lost.
Well, we did the truncate to shrink it, so it did extend it.
But now where is that extension thing that's been added?
Where did it go?
Well, it was just empty letters that it actually the trunked has added to this file.
It is the act letter signs to just to make it bigger.
Right now, we do not know how to use VI ed.
So by the time we'll use the VCR, Ed, you will know how to.
Vibha But for now, just to show you, we could do V.I. Sign fell and hit enter and you will see right
here all these add signs, these all add signs were added because when we extended the file, so operating
system said now you're extending, I have to put it something in there.
Right.
But I don't know what it had before, but I'm going to add something, so make it bigger.
So that's why you see it anyway.
So if you are using VI right now and you want to get out, hit, escape, shift colon.
Q.
Bang, which is right above number one and hit, and you will get out of the ice anyway, don't get
into the right now if you're not familiar with it, will cover it later on.
So, anyway, I wanted to cover this trunked I hope you understand how trunked works now tried out different
three different files, different contents in a file and see if you get familiar with it.