Skip to main content

First off, this isn't the only method to achieve the outcome of emptying a file.

Using a symbol : is a shell built-in command that is essence equivalent to the true command and it can be used as a no-op (no operation).  It can be used as follows:

# : > filename.txt

OR 

# true > filename.txt

 

My initial file was as follows:

21548342 16 Mar 20:27 code.log

Post using the command 

: > filename.txt

The response was 

0 16 Mar 20:27 code.log

Related articles

Andrew Fletcher16 Jan 2025
get IP address from terminal OSX
When troubleshooting network issues or configuring devices, knowing your IP address can be essential. Whether you're connected via Wi-Fi, Ethernet, or tethering through a mobile provider, macOS offers powerful built-in tools to quickly identify your IP address. Here's a practical guide tailored to...