I am new to linux, when I typed "vi FILE1" I was able to open VI editor. I added some data and I want to save the file and I tried :w but it threw me an error.
"file1" E212: Can't open file for writing
Press ENTER or type command to continue
why I am not able to save it?
I read it some where that I need permissions for that. While installing ubantu... I created and User and password with which I login.
Wont that user have admin privilages? what do I have to do to go further?
Change the permissions of the file concerned so that other users can edit the file, e.g. create a new group (sudo groupadd newgroup), put the users who are to be allowed to edit the file into that group (sudo adduser user newgroup), make the file group owned by the new group (sudo chgrp newgroup FILE1) and make the file writeable by the group (sudo chmod g+w FILE1)
2, Even if you do not want to give your users access to sudo to do anything they like (very wise!) then you can allow users to edit this one file in particular as root by using sudo with or without providing these users having to provide a password, e.g. run visudo:
$ sudo visudo
and enter the line:
some_user ALL = NOPASSWD: /usr/bin/vi /path/to/FILE1
Or to allow all users in a group (newgroup in this example) to edit the file then add:
%newgroup ALL = NOPASSWD: /usr/bin/vi /path/to/FILE1
Replace NOPASSWD with PASSWD if you want them to still provide their own password before being able to edit the file.
Note the full path to vi so the user cannot write a script called vi and run it as root and the file to be edited is also fully pathed.
The user (or users in newgroup) can then run:
sudo /usr/bin/vi /path/to/FILE1
to edit FILE1 as if they are the root user with or without having to provide a password depending on what you put into the sudoers file.
You need a space after 'cp' and between the source and destination.
The destination can be either a file name or a directory[folder]
The source name can be absolute or relative to the current directory.
You need to have read permissions for the source file, and write permissions for the destination directory.
The vi text editor has three modes: command mode, input mode, and ex mode.
Command mode
When starting, vi begins in command mode. If you are ever unsure which mode you're in, press Esc to return to command mode. In command mode, you can move around with the arrow keys, or by using the vi movement keys, as follows:
h left j down k upl right
Several vi commands are listed in the table below:
CommandAction Ctrl-bGo back one page Ctrl-fGo forward one page xDelete the character the cursor is on Shift-xDelete the character before the cursor ddDelete the current line Shift-dDelete everything from the cursor to the end of the line uUndelete a line you just deleted Shift-uUndo all changes to the current line Shift-z-zSave your file and exit the vi editor
Note: In command mode, you can type a number before pressing a command key to repeat the command multiple times. For example, to delete eight lines from the cursor position, you could press 8 and then type dd .
Input mode
The input mode lets you insert or append text. To insert text before the cursor's current position, in command mode, press i . Similarly, to append after the cursor, you can type a . Remember that you can't move around with the cursor keys in this mode. When you're done entering text, press Esc to go back to command mode.
Ex mode
The ex mode is an extension of command mode. To get into it, press Esc and then : (the colon). The cursor will go to the bottom of the screen at a colon prompt. Write your file by entering :w and quit by entering :q . You can combine these to save and exit by entering :wq . However, if you're finished with your file, it's generally more convenient to type Shift-z-z from command mode.
For a more thorough list of vi command keys, see A quick reference list of vi editor commands.
:D:cool:
chinnanji@ubuntu:~$ mkdir newfolder
chinnanji@ubuntu:~$ cd newfolder
chinnanji@ubuntu:~/newfolder$ mkdir folder2
chinnanji@ubuntu:~/newfolder$ cd folder2
chinnanji@ubuntu:~/newfolder/folder2$ touch file1 file2
chinnanji@ubuntu:~/newfolder/folder2$ ls
file1 file2
chinnanji@ubuntu:~/newfolder/folder2$ cd ..
chinnanji@ubuntu:~/newfolder$ cd ..
chinnanji@ubuntu:~$ cp /folder2/file2 /newfolder/file1
cp: cannot stat `/folder2/file2': No such file or directory
chinnanji@ubuntu:~$ cp /folder2/file2 /newfolder/
cp: cannot stat `/folder2/file2': No such file or directory
but when I tried to do it with out any slashes... it created a newfolder again.
please correct me
---------- Post updated at 11:35 AM ---------- Previous update was at 11:26 AM ----------
Hi Hannan,
Thanks for the handy list of commands. Till now I used to think that we have only two modes... command mode and text editor mode. the extension mode is interesting. thanks again
By putting the / at the beginning of the copy command, you are saying that the file is in a directory at the very top of the file system hierarchy. If you leave the leading slash off the cp command then the file(s) will be located relative to the current directory.
You should also change the permissions on directories that you have created so that you do not need to use the root account to write files.
In Ubuntu one does not normally need the root password because you use sudo instead, so my mentioning root password applies to other industry Unix es.
In Ubuntu your account is an administrator account by virtue of being in the admin group. My account in Ubuntu is in the following groups:
tony@laptop:~$ groups
tony adm dialout cdrom plugdev lpadmin admin sambashare newgroup
tony@laptop:~$
On the ~/.exrc file question you either edit it using vi to add the "set number" line OR you use the echo method to add it to the end of the file, either way if there was no ~/.exrc file presnet before then it should only contain the line:
.exrc is located in your home directory. This is the directory where you are placed when you first login.
The ~ (tilde) character is a short form for "my home directory", so
vi ~/.exrc
will edit the .exrc in your home directory whether you are in it or not.