Visit Our UNIX and Linux User Community


Why can't I save a VI file after entering data?


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Why can't I save a VI file after entering data?
# 1  
Old 02-08-2010
Why can't I save a VI file after entering data?

Hi

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?

Thanks in advance
# 2  
Old 02-08-2010
No, tjhat user does not have admin privilege.

You can use "sudo vi FILE1"
# 3  
Old 02-08-2010
Hi thanks Tony.

It worked. but how can I give admin privilages to a new user created? or already existing user in linux.

PS: I am using UBUNTU
# 4  
Old 02-08-2010
You an either

1. 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:
Code:
$ sudo visudo

and enter the line:
Code:
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:
Code:
%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:
Code:
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.

HTH

Last edited by TonyFullerMalv; 02-08-2010 at 06:24 PM..
# 5  
Old 02-09-2010
Hi TonyFullerMalv,

Thank you very much for the detailed explanation with the commands.

---------- Post updated at 11:30 PM ---------- Previous update was at 11:27 PM ----------

Please help me with one more question. I am trying to copy files from one folder to another. but it is not working

cp/file1/homefolder/destinationfolder

or

cp/file1/homefolder/destinationfolder/file2

I know these are wrong. But please correct where these are wrong.

Thanks in advance
# 6  
Old 02-09-2010
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.


Code:
cp /homefolder/file1 /destinationfolder/file2

# 7  
Old 02-09-2010
Hi thanks for the code.

But to gain the permissions shall I use sudo all the time?

Previous Thread | Next Thread
Test Your Knowledge in Computers #210
Difficulty: Easy
Routing protocols like OSPF calculate the shortest route to a destination through the network based on a computer algorithm.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Get a data and save

If I have a A.log 1 Air Flow Monitor : 34.070 Degrees C 2 Air Flow Monitor : 41.730 Degrees C 3 Air Flow Monitor : 35.340 Degrees C 4 Air Flow Monitor : 33.370 Degrees C 5 Air Flow Monitor : 36.770 Degrees C 6 Air Flow Monitor : 45.910 Degrees C 7 Air Flow Monitor ... (1 Reply)
Discussion started by: sabercats
1 Replies

2. UNIX for Advanced & Expert Users

How to save a data of a file into a variable?

My requirement is to read a column data from a file & save it in a variable for each row & process it. I am using the below code- Leadlines="$TGTFILE/Error.txt">>$log_file while read line do id = ` echo $line | cut -d "," -f1 ` email = ` echo $line | cut -d "," -f2 ` ----------- done My... (2 Replies)
Discussion started by: saga20
2 Replies

3. Shell Programming and Scripting

Open Text file input data and save it.

Hi Guys, I have blank file A.txt I will run the script xyz.sh First i want to open a.txt file... Now i will enter some data like XYZ ABC PQR .. Save it and keep continue my script.... END of my script. Thanks (1 Reply)
Discussion started by: asavaliya
1 Replies

4. Shell Programming and Scripting

Get Permissions and save to data

Hi all; I have the following code which gives me kind of what I need: #!/usr/bin/perl use Fcntl ':mode'; # if ($ARGV ne "") { $filename = $ARGV; } else { print "Please specify a file!\n"; exit; } # if... (2 Replies)
Discussion started by: gvolpini
2 Replies

5. Solaris

Login delay after entering id (40 secs) same after entering pw

Hi all, I have just installed Solaris 10 on an old Fujitsu Primepower 650 which has been wiped clean. I haven't installed anything apart from the OS yet, so the machine is 99% idle. I get long delays when logging in, first after entering the id then another long delay after entering a valid... (8 Replies)
Discussion started by: longjon
8 Replies

6. Shell Programming and Scripting

How to add data from 2 input files and save it in 1 output file

Hi, i have 2 input files which are file1.txt and file2.txt. I need to extract data from file1.txt and file2.txt and save it in file3.txt like example below:- File1.txt ID scrap1 Name scrap1 start 1 end 10 ID scrap2 Name scrap2 start 11 end ... (4 Replies)
Discussion started by: redse171
4 Replies

7. Shell Programming and Scripting

perl-data from file save to multidimensional array

i have a file,like 1 3 4 5 6 7 8 9 i want to save it into an array. and then i want to get every element, because i want to use them to calculate. for example: i want to calculate 1 + 3. but i cannot reach my goal. open (FILE, "<", "number"); my @arr; while (<FILE>){ chomp;... (1 Reply)
Discussion started by: pp-zz
1 Replies

8. Shell Programming and Scripting

select data from oracle table and save the output as csv file

Hi I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string,... (2 Replies)
Discussion started by: rdhanek
2 Replies

9. Shell Programming and Scripting

Data fetched from text file and save in a csv file

Hi i have wriiten a script which fetches the data from text file, and saves in the output in a text file itself, but i want that the output should save in different columns. I have the output like: For Channel:response_time__24.txt 1547 data points 0.339 0.299 0.448 0.581 7.380 ... (1 Reply)
Discussion started by: rohitkalia
1 Replies

10. Filesystems, Disks and Memory

Can ZFS Save my Data

Hello, Our RAID and server recently crashed and we are trying to recover our data. The problem appears to be that the Veritas File System/Logical Volume Manger became corrupt on our RAID. We are down to our last option, which is to run some Veritas commands that "may" result in data loss. ... (1 Reply)
Discussion started by: stringman
1 Replies

Featured Tech Videos