mac

Mac – How to clear a file’s contents using Terminal command

A quick trick to empty a file using Terminal on Mac.

1. Open Terminal

2. enter the following command in Terminal

cat /dev/null > fileName

If you get a warning Permission Denied you can do the following trick.

sudo sh -c 'cat /dev/null > fileName'

Published by Jonathan Whiting

I enjoy sharing what I am learning and hopefully it's of interest and help to you. I live in Canada with my wife. Follow me on Twitter.

2 comments on “Mac – How to clear a file’s contents using Terminal command”

  1. Gijs says:

    `echo “” > fileName`

    Also does the trick.

    1. Jonathan Whiting says:

      Hi Gijs,

      Great tip, thanks for posting

Leave a Reply to Jonathan Whiting Cancel reply

Your email address will not be published. Required fields are marked *