Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
After launching vi, writing some text and attempting to save it I get the error message "Can't open file for writing." Since I did not open a file to begin with don't know what this is in reference to. Does one have to specify the filename before trying to save it? That is issue the command vi <filename> first? The method that I tried to save the file is as follows:
1:Go into command mode using the Esc key
2:Then issue the :w command followed by the filename and pressing the Enter key.
3: What follows is the noted error message or the option of continuing with the command. This implies that the command is incomplete. Pressing the Tab/Ctrl keys for some hints does not help and I could not see any infomation in the Man pages on this. TIA for suggestions on resolving this issue.
After I issue the :w command do I have to specify the absolute path to where the file should be saved also?Or, if I am in my Home directory will not vi save it to there by default?
if your in your home directory, it will save there by default.. but be sure not to just issue :w , you need to add the q! also so it quits as well.. well if your done with the file.
Originally posted by TacKat If you do a ":wq" you don't really need a "!" on the end. ":q!" just forces a quit even if you haven't saved, which you just did.
I tried the :wq command followed by the filename and still get the same error message. When I try to specify a path after the filename I get the message that only one name is allowed per file. Don't know what, if anything, I may be doing wrong unless someone has overlooked something. I wonder whether or not the filename should precede the :wq command?
When you first open vi you should state the name of the file you would like to save it as. For example: #vi howtousevi# would be opening a new file and naming it "howtousevi". Then at the end when you try to save with :wq it will simply right over the empty file named "howtousevi". I don't know if this will help or not, but good luck.
It seems that it says "can't open file for writing" when you don't have write access to the place it's trying to write it to.
However, if you simply type
:w /home/username/filename" it should work.
What version of VI are you using?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.