# delete a very large file from UFS partition



## m4rtin (Jul 13, 2010)

I have a remote production server, where 40GB slice is allocated for var:

```
/dev/ad1s1f     40G     40G   -4G   110%    /var
```

Filesystem for _/var_ partition is UFS and it's mounted with local and noatime options. There is a 37GB log file in the _/var_ partition. As it's so huge and there seems to be somesort of capacity overload already, is it safe to delete this large file by just doing:

```
rm -rf /var/log_file
```

If not, please give other suggestions/warnings


----------



## jb_fvwm2 (Jul 13, 2010)

```
/bin/rm -iv /var/log_file
```
 if it is a file


----------



## fronclynne (Jul 13, 2010)

If it's still being written to, the space will probably stay allocated.  YOu need to kill whatever's doing that.


----------



## gordon@ (Jul 13, 2010)

Or just truncate the file.

`# : > /var/log_file`

This will free up the space even if there is something that is currently writing to the file.

That's colon, greater sign, name of log file.


----------



## m4rtin (Jul 13, 2010)

*fronclynne*, I have already killed this logging process so the file will not get bigger.

*gordon@*,
could you please explain this 

```
# : > /var/log_file
```
..command a little? As I understand, this redirects( > ) colon( : ) into the /var/log_file, thus writing everything in this /var/log_file over(there will be only this colon in /var/log_file). Am I correct? Or is colon some sort of special character?

*jb_fvwm2*,
as I have stopped the logging command, I'll go with this */bin/rm -v /var/log_file* command


----------



## DutchDaemon (Jul 13, 2010)

[cmd=]> /var/log_file[/cmd] or [cmd=]cp /dev/null > /var/log_file[/cmd] is enough, really.


----------



## wblock@ (Jul 13, 2010)

DutchDaemon said:
			
		

> [cmd=]> /var/log_file[/cmd]



Not from csh/tcsh, unfortunately:


```
% > /var/log_file
Invalid null command.
```



> or [cmd=]cp /dev/null > /var/log_file[/cmd] is enough, really.



Careful, this could turn into "how many ways are there to do this". 

*m4rtin*, see this:
`# man sh | less "+/null command"`


----------



## gordon@ (Jul 14, 2010)

Colon is a null command in bourne and c-style shells. As such, the output of the command (nothing) is then redirected to the file after it is truncated. I suppose using `# cat /dev/null > /var/log_file` would also work.


----------



## SirDice (Jul 14, 2010)

gordon@ said:
			
		

> I suppose using `# cat /dev/null > /var/log_file` would also work.



It would never finish as there will be no end-of-file


----------



## DutchDaemon (Jul 14, 2010)

cp is the way to go! (please don't use mv there ...)


----------



## gordon@ (Jul 15, 2010)

SirDice said:
			
		

> It would never finish as there will be no end-of-file



Sure it'll finish. /dev/null is nothing but EOF's. You are thinking of /dev/zero which will keep going until the end of time (or you fill up your disk).


----------



## gordon@ (Jul 15, 2010)

DutchDaemon said:
			
		

> cp is the way to go! (please don't use mv there ...)



I wouldn't recommend the command you cite:

`% cp /dev/null > /var/log_file`

This will produce an error (but will still truncate the file since it doesn't put anything to stdout, just stderr).

At that point using `% : > /var/log_file` is the same. But so is `% true > /var/log_file` or `% false > /var/log_file` or `% /path/to/command/with/null/output > /var/log_file` for that matter.


----------



## DutchDaemon (Jul 15, 2010)

gordon@ said:
			
		

> I wouldn't recommend the command you cite:
> 
> `% cp /dev/null > /var/log_file`
> 
> This will produce an error (but will still truncate the file since it doesn't put anything to stdout, just stderr).



Yeah, that was a brain fart. It should be [cmd=]cp /dev/null /var/log_file[/cmd]

There's also [cmd=]echo > /var/log_file[/cmd]


----------



## fronclynne (Jul 16, 2010)

Hah, this could go all night.

[cmd=""]truncate -s0 /var/log_file[/cmd]
[cmd=""]truncate -r /dev/null /var/log_file[/cmd]


----------

