How to prevent a file from being overwritten using the tcsh shell on Linux.

Posted: August 30, 2013. At: 11:58 PM

This example using the set noclobber command prevents existing files from being overwritten.

9:18am homer /home/homer/Documents ) set noclobber
9:18am homer /home/homer/Documents ) ls ip.txt
9:18am homer /home/homer/Documents ) echo "hello" > ip.txt
ip.txt: File exists.

But you can still erase the file with the rm command.

9:20am homer /home/homer/Documents ) rm ip.txt
11:27pm homer /home/homer/Documents ) ls ip.txt
ls: cannot access ip.txt: No such file or directory

This is how to override this setting if need be. Use the echo “hello” >! ip.txt command to force a write to an existing file.

11:46pm homer /home/homer/Documents ~/Documents> echo "hello" > ip.txt
11:46pm homer /home/homer/Documents ~/Documents> echo "hello" > ip.txt
ip.txt: File exists.
11:46pm homer /home/homer/Documents ~/Documents> echo "hello" >! ip.txt

This is how I got my awesome tcsh shell prompt. This one is rather nice.

set prompt = "%t %n %/ %~%# "

Get more information about the tcsh shell here:

What do you think?

Leave a Reply

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