In: Computer Science
Linux Operation
For the following exercises, ensure the following regarding the student1 and student2 accounts:
Also note that, the term “home directory” below, if not specified in detail, refers to the home directory of the current user (e.g. /home/student1 for the student1 account). This does not specify just the “/home” directory.
*** On the lab answers – be sure you use the form fields, so that your answers are show in red ***
SECTION 1 – Absolute/Relative Paths, Files and Directories:
.
Now cd to the /tmp directory. Enter two commands, which will change your directory to the home directory for student1:
and
Verify these two commands work by displaying your current directory after each one is run.
List the contents of the /tmp directory using a relative path name: .
After listing the contents of a directory, does your present working directory change? .
What command changes your present working directory? .
Explain what “~” represents: .
.
Create another file called labfile2 with the touch command in the /tmp directory using an absolute path name. What command did you use: .
Now touch one of these files again. What, if anything is different in the file’s characteristics? .
In what storage units are files displayed in unix? .
Ensure you are in your home directory for student1. Use the tail command and a relative path to display the last 5 lines of the /etc/passwd file. What command did you use: .
Ensure you are in your home directory for student1. Use the head command and an absolute path to display the first 5 lines of the /etc/group file. What command did you use: .
Change your current directory to the subdir1 directory using a relative pathname. What command did you use: .
Change back to your home directory for student1. Create a file called labfile3 in this subdir1 directory using the touch command with a relative pathname. What command did you use:
.
.
To create user with 022 permissions by default:
You can setup umask in /etc/bashrc or /etc/profile file for all
users. By default most Linux distro set it to (022). Open
/etc/profile or ~/.bashrc file, enter:
# vi /etc/profile
sudo useradd -m -d /home/student1 student1
sudo useradd -m -d /home/student2 student2
sudo su student1
sudo usermod -a -G www-data student1
sudo chmod -R 755 /home/student1
sudo chmod -R 755 /home/student2
sudo su student1
cd ~/.
/home/student1
cd /tmp
cd ~/.
cd /tmp
ls -ltr
cd /
cd /tmp
touch labfile1
touch /tmp/labfile2
cd /home/student1
echo line1, line 2, line3 , line4 , line 5, line 6 , line 7, line
8, line 9, line 10 >> /tmp/labfile1
ls -ltr /tmp
ext4
cd /home/student1
tail -n 5 /etc/passwd
head -n 5 /etc/passwd
mkdir subdir1
cd subdir1
cd .
cd subdir1
mkdir labfile3
ls –al subdir1
dipalys files in directory
ls –ald subdir1
difplays directory information