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

Posted: July 28, 2017. At: 11:58 PM. This was 7 months ago. Post ID: 6186
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

How to use noclobber with the tcsh shell on UNIX and Linux

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

2:04am ubuntu /home/ubuntu ~> set noclobber

Now if I try to redirect to the file, this happens.

2:04am ubuntu /home/ubuntu ~> echo "" > chan.c
chan.c: File exists.

This prevents accidental file overwriting when experimenting with redirection.

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

2:08am ubuntu /home/ubuntu ~> rm chan.c
2:08am ubuntu /home/ubuntu ~> ls chan.c
ls: cannot access chan.c: 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.

2:09am ubuntu /home/ubuntu ~> echo "hi" >! chan.c
2:10am ubuntu /home/ubuntu ~> cat chan.c

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:

No comments have been made. Use this form to start the conversation :)

Leave a Reply