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

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:

Post a Comment

Your email is kept private. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>