Because deleting files and directories is quite common, it is usually

wise to configure aliases file (executed when logged in) as ows:

alias nn='rm -i'

alias mv='mv -i'

alias cp='cp -i'

When you issue the command rm at the command prompt you would in truth issue the command rm -i.

Tasks

  1. Try to use alias in your own system. Is it OK?

File Security

Objectives

You should be able to:

- Display file and directory permissions

- Define the standard permission types (read/write/execute)

-Use the chmod command to change permissions with symbolic mode or octal mode values

-Determine the default permissions assigned to newly created files and directories with umask

Modifying Permissions

File permissions can be modified by using the command chmod (change mode). User permissions are referred to by the letter u (u=user owner), the group with the letter g (g=group) and all others with the letter o (o=others). When modifying all permissions, the letter a (a=all) is used

The plus sign (+) is used to add permissions and the minus sign (-) to take them away. When you want to modify the file permissions, so that only the issued permissions come into effect, use = (equals).

chmod a+rfileAssign read permissions to the file to everyone

chmod go-rwx fileRemove all permissions to the file from everyone else apart from the user

chmod u=rx file Give the user read and write permissions to the file.

chmod 700 file Give only the user read, write and execute permissions

Tasks

Complete or answer the following:

1.Execute the following commands:

$ mkdir ~/perm

$ cd /etc

$ cp group passwd motd vfstab shadow ~/perm

$ cd

$ cp -r /etc/skel perm

When trying to copy /etc/shadow, an error message was displayed. Why?

2. Create a new file and a new directory.

What are the default permissions given to the new file?

What are the default permissions given to the new directory?

3. Using symbolic mode, add write permission for the group to the motd file.

4. Using octal mode, change the permissions on the motd file to -rwxrw----.

5. Using octal mode, change the permissions on the group file to add write permission for others.

6. Create a new file called memo in your home directory. Write your name.

How can your friend read this file from your home directory. Last, change your permission back.

7. Check your current default permission mask.

Links

Objectives

You should be able to:

- Define the soft and hard links

- Determine which differences are

Link files by soft and hard

ln file1 file2Creates a hard link named file2 which

refers to the same i-node as file1

ln -s file1 file2Creates a soft link named file2 which refers

to the file named filel

Tasks

Complete or answer the following:

1. Make a file named original in your home directory. You can write some lines of texts.

Create a soft link orisoft and a hard link named orihard.

2.Compare the size of the orisoft file with the orihard file? What can you notice?

Who is bigger? Why?

3. Next, add a few lines of text to the original.

Check if you can see the additional lines of text also within the link files.

4. Add some extra lines to Orisoft. Can they also be seen in original and or

orihard?

5. Can you make a hard link from original to the /tmp directory?

6. Delete the original file. Did you at the same time delete the orisoft and / or orihard files? Did anything change?

1

Unix Lab3

Markku Nuutinen