In: Computer Science
This assignment includes the creation of a text document using Vi Editor and changing permissions to access the new file.
1. Open terminal and type vi and hit enter to open vi editor.
2. Press i to enter insert mode.
3. Now type the content.
4. After writing the text press escape twice and enter a colon followed by wq.
5. After typing :wq enter the name you want to give to the file as shown in image.
6. Hit enter after typing the file name and your file will be saved and you'll be out of the vi editor.
Displaying the contents:
cat: cat command concatenates the files and prints the output. When we give only a single file then it just prints its contents to the screen.
head: head command displays the first ten lines of the given file.
tail: tail command displays the last ten lines of the given file.
Setting file permissions:
First let's check the permission of our file vi.txt using the command ls -l
In the above output the first - represents that the file isn't a directory, rw- represents read and write permissions for user, r-- represent only read permission for group and last r-- represents only read permissions for others.
To give read, write and execute permissions for the file, we give the command as:
chmod ugo+rwx filename
ugo stands for user, group and other
rwx stands for read write and execute.
Now, the file vi.txt is given read, write and execute permissions for user, group and others.