LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to reduce the size of a file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-reduce-the-size-of-a-file-841477/)

abhinav4 10-31-2010 12:37 AM

How to reduce the size of a file?
 
How to reduce the size of a file. Is truncate related to this?If so can someone explain please

TobiSGD 10-31-2010 12:40 AM

You can reduce the size of a file by compressing it. In Linux you can use tools like gzip, bzip2, lzma, zip, rar and many more for this purpose.
Have a look at least at man gzip and man bzip2.

vikas027 10-31-2010 12:47 AM

Hi Abhinav,
Yes the Truncate is sometimes related to file size. It means you delete all the contents of the file thereby making the size of the file 0 bytes.

It is often done as
Code:

cat /dev/null > /your/file/name

abhinav4 10-31-2010 12:54 AM

Quote:

Originally Posted by vikas027 (Post 4144711)
Hi Abhinav,
Yes the Truncate is sometimes related to file size. It means you delete all the contents of the file thereby making the size of the file 0 bytes.

It is often done as
Code:

cat /dev/null > /your/file/name

Actually sometimes when I see the log files which were archived after few lines it shows the message output truncated.... and then again it continues to show the later part. So just guessing how to perform this.

raviteja_s 10-31-2010 09:02 AM

hi,

echo " " > /var/log/messages

arizonagroovejet 10-31-2010 11:13 AM

Quote:

Originally Posted by raviteja_s (Post 4144951)
hi,

echo " " > /var/log/messages

That replaces the contents of /var/log/messages with a single space character.

There are lots of ways of making a file zero length that involve a lot of unnecessary typing. You can just use

Code:

>/var/log/messages

Davethesnake 10-31-2010 11:23 AM

yes you can reduce the sie of a file also by discarding unneccessary code/comments--refer to linux manual

abhinav4 10-31-2010 10:40 PM

Truncate a file
 
How do we truncate a file?

chrism01 11-01-2010 12:36 AM

What language are you using eg C, shell ... ?

abhinav4 11-01-2010 09:36 PM

Quote:

Originally Posted by chrism01 (Post 4145476)
What language are you using eg C, shell ... ?

shell

arizonagroovejet 11-02-2010 05:15 AM

Quote:

Originally Posted by abhinav4 (Post 4146363)
shell

Then you've been given three methods already in this thread. If none of them do what you want, I think you need to explain in greater detail what you mean by 'truncate'. The assumption has been that you mean 'make zero length'.

Mark1986 11-02-2010 05:19 AM

Quote:

Originally Posted by arizonagroovejet (Post 4146667)
Then you've been given three methods already in this thread. If none of them do what you want, I think you need to explain in greater detail what you mean by 'truncate'. The assumption has been that you mean 'make zero length'.

And if your problem is solved, please state your solution and mark the thread as SOLVED. Also please give the reputation to those who helped you.

rew 11-02-2010 05:48 AM

The Unix system call "truncate" will do exactly that, but you can specify a number of bytes. So you can have a file called MyFile with
line 1
line 2
line 3

which has 7 bytes per line. So if I run
truncate 14 MyFile
only the first two lines are left.

I wrote my own version of the "truncate" program before this became a standard Linux utility. Here is a thread that mentions a source for the standard program (which happens to have the same interface as the one I wrote) http://mandrivausers.org/index.php?/...a-file-solved/


All times are GMT -5. The time now is 05:33 PM.