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.
Am trying to learn vi but seem to have come up with an initial problem.
I have been following a ryanstutorial about learning bash, and I also have a Linux in easy steps, by Mike McGrath at hand.
I am using Linux Mint 19 XFCE.
I am able to insert text. But when I try and save and exit, I run into problems with all the different commands that I can find in my two sources. Thus:
ZZ produces the message E212: Can't open file for writing
[ctrl] x produces the same message
:qa brings up the messages E37: No write since last change
and E212 - ditto - for buffer "test"
:qa! takes me out of vi and back to the shell prompt
:w - which I found in McGrath, is no help either.
This is probably something very elementary. But, at my level of skill, insurmountable.
I always exit with wq. w writes out the text and q quits. q by itself doesn't work if the file is dirty; you get that warning about not having written since the last change. q! overrides that, but it means your changes aren't saved. Save that one for when you have made a mess of the file and you want to just cancel the edit altogether. To save your work use w for a file that already has a name or w filename for one that doesn't.
Thanks. I was doing the w and the wq - with Esc and the colon : - but the user-permission was the key. Tried it with sudo, and it worked. Now, is there a way in which I can open vi without needing to do the sudo thing each time?
Thanks. I was doing the w and the wq - with Esc and the colon : - but the user-permission was the key. Tried it with sudo, and it worked. Now, is there a way in which I can open vi without needing to do the sudo thing each time?
I don't recommend you try to supersede this. Yes, technically you can login as root, but there's a reason why the file permissions sometimes are even set to read-only for ALL users, including root, because you need to think about editing that file. You should make a copy of any files you intend to edit, if they are configuration type of files or profile files. If you edit it and find that things do not work, you can then use the former copy of return the file to it's original working form. Nothing wrong with keeping incremental backups, such as you are learning, editing, you make one change, it works. So then you try to make other changes, over time suddenly nothing is working, but you may find that reversing the one last change isn't sufficient, likely because you didn't re-check the ability to work at each juncture. This is very common when experimenting. Nothing wrong with it, but as far as uniformly allowing yourself to always be able to edit files that are protected? That's dangerous, even for those with great experience, we all make errors. If you're editing files owned by your username, within your user home directory, then there should be no protection issues at all, unless you've tinkered with your default umask or something.
The whole point of the Linux permissions system is that it allows you to explore your system safely because you are not root and therefore cannot do any harm. It also prevents malware that you might download from the internet in your name from doing any harm to your system. Becoming root just so you can ignore permissions is reckless, and so is changing permissions to save a few keystrokes. Distro developers take great pains to ensure that system files and directories have correct permissions to ensure trouble-free working. I've been using Linux for more than fifteen years now and I leave permissions well alone because I know they are there for my protection.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.