Emptying a file (bring the size of the file down to 0 , or close to 0)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Emptying a file (bring the size of the file down to 0 , or close to 0)
# 1  
Old 07-13-2010
Emptying a file (bring the size of the file down to 0 , or close to 0)

Hi

I tried to empty an existing file (bring the size of the file down to 0). When I used “> myFile” or “cat </dev/null >myFile”, when I do a “ls –la”, the file size shows as 0.

I then wrote 540 lines to the file, and then opened it using vi, I see something like this:
"myFile" 540 lines, 6533391 characters (6490635 null)

Seems like the commands above did not realease the disk space. They simply converted all characters to null characters (which are still taking up space). Does anyone know how to empty a file and make the file size go to zero (or close to zero)?

Thanks a lot Smilie

Tom
# 2  
Old 07-13-2010
what happens if you: # touch <filename>?

edit: just took a look at the man page - there doesn't seem to be a flag to recreate the file only creates if it's not there in the first place.

Last edited by Celtic_Monkey; 07-13-2010 at 11:46 AM..
# 3  
Old 07-13-2010
Quote:
Originally Posted by Celtic_Monkey
what happens if you: # touch <filename>?
Unfortunately it's the same result.
# 4  
Old 07-13-2010
Perhaps the file is open by a program which needs to be stopped before nulling the file?

Code:
fuser -f filename

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Bash/vi: Make file go away once I close it.

Hi Everyone, It's a little difficult to explain what exactly I am looking for. When I open a file in vi, and then close it, I get back the prompt, but I can still see the file on top. I don't want that. I want to be able to see all the previous commands which I have typed. For example: I... (4 Replies)
Discussion started by: the_learner
4 Replies

2. Shell Programming and Scripting

Bring back a file changed with sed

Hello everbody I changed one of my important files with a false sed statement by mistake now I lost my file and I hope I could bring it back what I did was: sed '/^..//' a > myfile myfile should have been another file like b ot something I know I also forgot to place an 's' to the... (5 Replies)
Discussion started by: miriammiriam
5 Replies

3. UNIX for Advanced & Expert Users

Close file descriptor without terminating process

Can any help me in finding the way to close opened file descriptor in Solaris ,without killing process. As accidently a file was removed which was opened by a process. Much thanks in advance :) (11 Replies)
Discussion started by: nitj
11 Replies

4. Shell Programming and Scripting

Sed emptying file when i use for search replace operation

Hi Friends I am new to sed programming , i found that the below code can search for the $ToSearch and Replace it with $ToReplace ( $ToSearch and $ToReplace are my variables in my script ) sed "s/$ToSearch/$ToReplace/" $file > $output mv $output $file In testing the script i found that... (3 Replies)
Discussion started by: rakeshkumar
3 Replies

5. Shell Programming and Scripting

[Solved] SFTP error - Couldn't close file: Failure

I am trying to send a file from my 9000 box to a vendor using sftp and I am getting this error: Couldn't close file: Failure Here are the results of my automated script: Connected to yyy.com. sftp> pwd Remote working directory: / sftp> cd xxxxx/yyyyy_TEST/TEST sftp> put FILE FILETEST... (1 Reply)
Discussion started by: nickg
1 Replies

6. AIX

Impacts of emptying /var/adm/wtmp file ?

In our operating procedures, if a workstation has a space problem in the /var filesystem, one of the most frequent case we were told is the size of the /var/adm/wtmp file. Someone once told me it is dangerous to do this. Is it ? I cannot say for certain that whomever wrote that procedure is... (2 Replies)
Discussion started by: Browser_ice
2 Replies

7. Windows & DOS: Issues & Discussions

Can DOS close an open file?

I'm trying to setup a cron job for my brother that goes out to the web and retrieves an excel file and overwrites the existing copy on his desktop. The problem I'm facing is I have to kill the process (excel.exe) if the file is open while the batch file runs, otherwise, it will create another copy... (2 Replies)
Discussion started by: quattro20v
2 Replies

8. Shell Programming and Scripting

file size comparision local file and remote file

Hi, I have written a script which would FTP a dump file to the FTP server and log the whole activity into a file. to confirm the success of the file copy i grep for "226 file receive OK" and then send out an email saying success. Now i want to make sure the bytes of the local file and... (4 Replies)
Discussion started by: dba.admin2008
4 Replies

9. Shell Programming and Scripting

Null values after emptying a log file

Hi, I have a log file which is constantly being written to by some process. I need to clear that log file on a daily basis. The problem is that when I issue this command: echo "" > logfile.log the file gets filled with nulls thus increasing the size of the file. Is there a way to... (2 Replies)
Discussion started by: kasie4life
2 Replies

10. UNIX for Dummies Questions & Answers

File status - open/close ??

Is there any commands in UNIX, like isopen(),isclose() to know whether a file has been opened for read/write purpose.? Thanks (3 Replies)
Discussion started by: Pal
3 Replies
Login or Register to Ask a Question