Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've used shell environments in the past where the text editor "nano" will warn me if I don't have write permissions on a file when I open the file for editing. This saves me a lot of time when I forget to type "sudo" beforehand and then spend time editing the file only to have to do all over it again.

I'd like to duplicate this behavior on several other servers, but don't see anywhere in the nano manpages where this is an option.

share|improve this question
Are you sure it was nano? I've only seen this behavior with VI and VIM. – Josh Budde Sep 30 '09 at 19:43
up vote 2 down vote accepted

Why not replace the nano command with a script that checks to see if you have write permissions and automatically call sudo nano if you don't? Saving you even more time!

You might want to have the script output that you don't have write permissions before calling sudo nano so that you're not wondering why you're being asked for your password.

share|improve this answer
Oh, it must have been a script. In fact, here's one I can modify: – scotts Sep 30 '09 at 20:29

I modified the script linked to in the correct answer to check whether the user has write permissions for files that don't exist (checks the proper directory permissions), and a few other updates.

This is a modification of:


[ $# -eq 0 ] && exit 1

if [ -w "$FILE" ] || ( [ ! -e "$FILE" ] && [ -w `readlink -f $FILE | grep -o '/.*/'` ] ) ; then
   nano $FILE
   tput bel
   echo "WARNING: You do not have write acess to $FILE"
   echo -n "Continue? y/[n]: "
   read REPLY
   if [ $REPLY ] && [ $REPLY == "y" ] ; then
        nano $FILE
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.