LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-31-2010, 12:37 AM   #1
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Rep: Reputation: 0
Question 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
 
Old 10-31-2010, 12:40 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
1 members found this post helpful.
Old 10-31-2010, 12:47 AM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
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
 
Old 10-31-2010, 12:54 AM   #4
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Question

Quote:
Originally Posted by vikas027 View Post
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.
 
Old 10-31-2010, 09:02 AM   #5
raviteja_s
Member
 
Registered: Jun 2010
Location: India
Distribution: Redhat
Posts: 68

Rep: Reputation: 1
hi,

echo " " > /var/log/messages
 
Old 10-31-2010, 11:13 AM   #6
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by raviteja_s View Post
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
 
Old 10-31-2010, 11:23 AM   #7
Davethesnake
LQ Newbie
 
Registered: Oct 2010
Posts: 25

Rep: Reputation: -14
yes you can reduce the sie of a file also by discarding unneccessary code/comments--refer to linux manual
 
Old 10-31-2010, 10:40 PM   #8
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Question Truncate a file

How do we truncate a file?
 
Old 11-01-2010, 12:36 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,364

Rep: Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752
What language are you using eg C, shell ... ?
 
Old 11-01-2010, 09:36 PM   #10
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Question

Quote:
Originally Posted by chrism01 View Post
What language are you using eg C, shell ... ?
shell
 
Old 11-02-2010, 05:15 AM   #11
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by abhinav4 View Post
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'.
 
Old 11-02-2010, 05:19 AM   #12
Mark1986
Member
 
Registered: Aug 2008
Location: Netherlands
Distribution: Xubuntu
Posts: 87

Rep: Reputation: 11
Quote:
Originally Posted by arizonagroovejet View Post
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.
 
Old 11-02-2010, 05:48 AM   #13
rew
Member
 
Registered: May 2010
Posts: 36

Rep: Reputation: 3
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/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reduce the size of wpa_suppliments? sybercop Programming 1 11-10-2007 12:39 PM
How to reduce video file size? leosgb Linux - General 9 06-15-2007 12:43 PM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 06:55 AM
How to reduce voice-audio file size? WindowBreaker Slackware 9 02-04-2006 09:09 AM
help me reduce my OS size =/ xushi Slackware 29 12-01-2004 11:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration