theYinYeti Posted June 2, 2008 Report Share Posted June 2, 2008 (edited) I forgot to stop a TV recording, which resulted in a giant file taking up all remaining free space on disk. Now I want to keep only the first 12GB from this file. The disk is so full I can't free 12GB on it, to be able to use the "head" command. I know I can (and will) use something like "head --bytes=12000m FILE | ssh remoteuser@remotehost 'cat >TAIL-FILE'". But… I'd like to know how I can truncate a file to its first bytes when neither the network nor extra disk space is available. Yves. Edited June 3, 2008 by theYinYeti Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted June 3, 2008 Report Share Posted June 3, 2008 (edited) a quick search for linux and truncate revealed this links: http://linux.about.com/library/cmd/blcmdl2_truncate.htm which according to pbone.net is either in the ltp package: http://rpm.pbone.net/index.php3/stat/4/idp...0.i386.rpm.html or in the embutils package: http://rpm.pbone.net/index.php3/stat/4/idp...1.i586.rpm.html based on the description it does not move the file so it seems like what you are looking for. ciao! Edited June 3, 2008 by ramfree17 Quote Link to comment Share on other sites More sharing options...
theYinYeti Posted June 3, 2008 Author Report Share Posted June 3, 2008 a quick search for linux and truncate revealed this links: http://linux.about.com/library/cmd/blcmdl2_truncate.htm This is a C system call. I cannot use it directly. which according to pbone.net is either in the ltp package: http://rpm.pbone.net/index.php3/stat/4/idp...0.i386.rpm.html And those are just test cases for the kernel function that is called by the above system call. or in the embutils package: http://rpm.pbone.net/index.php3/stat/4/idp...1.i586.rpm.html based on the description it does not move the file so it seems like what you are looking for. I didn't notice this one before. It may indeed be what I'm looking for, even though it's deep under /usr/lib… Thanks, I'll try. Yves. Quote Link to comment Share on other sites More sharing options...
theYinYeti Posted June 3, 2008 Author Report Share Posted June 3, 2008 (edited) Excellent! :) It works: [yves@localhost ~]$ truncate usage: truncate size filename [filename...] [yves@localhost ~]$ echo "hello hello" >testfile [yves@localhost ~]$ echo "bye bye" >>testfile [yves@localhost ~]$ ls -li testfile 711918 -rw-r--r-- 1 yves yves 20 2008-06-03 10:27 testfile [yves@localhost ~]$ cat testfile hello hello bye bye [yves@localhost ~]$ truncate 10 testfile [yves@localhost ~]$ ls -li testfile 711918 -rw-r--r-- 1 yves yves 10 2008-06-03 10:27 testfile [yves@localhost ~]$ cat testfile hello hell[yves@localhost ~]$ Thanks again. Yves. Edited June 3, 2008 by theYinYeti Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted June 3, 2008 Report Share Posted June 3, 2008 cool! :) ciao! Quote Link to comment Share on other sites More sharing options...
Guest senyahnoj Posted October 23, 2008 Report Share Posted October 23, 2008 (edited) If you are using bash you can simply do: > filename not sure about other shells... Edited October 23, 2008 by senyahnoj Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted October 23, 2008 Report Share Posted October 23, 2008 If you are using bash you can simply do: > filename wouldnt that overwrite the whole file (aka redirection)? the original problem is to truncate a file up to a certain point so that the file contents is still usable and space is freed up. ciao! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.