Completed: / exercises

Tehtävät – Assignments

Finding instructions

Man Pages

Which shell command you'd give to get information about the passwd program (Note: you can get out of the manual pages by pressing q)

Warning: You have not logged in. You cannot answer.

Finding information from man pages

Open up the man page for the command grep. What option does the command need in order to print the line number before each matched line?
Warning: You have not logged in. You cannot answer.

Using search words

The command man can also be used to find man pages by search word. Which of the following commands may be used to find a list of man pages which include the word email in their name or description?
Warning: You have not logged in. You cannot answer.

The directory hierarchy

Current working directory

Which command shows you your current working directory?
Warning: You have not logged in. You cannot answer.

Moving in the directory hierarchy

Which command do you use to move in the directory hierarchy?
Warning: You have not logged in. You cannot answer.

Absolute pathnames 1

Move to your own home directory by using the command cd ~. Check that you are really in your home directory by using the command pwd. Now move to the directory /usr/share/doc by using absolute pathnames. What command did you use?

Warning: You have not logged in. You cannot answer.

Absolute pathnames 2

Move to the directory /var/spool/mail by using absolute pathnames. What command (and path) did you use?

Warning: You have not logged in. You cannot answer.

Relative pathnames 1

Move to your own home directory by using the command cd ~. Check that you are really in your home directory by using the command pwd. Now move to the directory /home by using a generic command that always takes you one step closer to the root in the hierarchy. What command did you use?
Write your answer below
Warning: You have not logged in. You cannot answer.

Relative pathnames 2

Move to the root directory by using the command cd /. Now change to the directory var by using relative pathnames. What command did you use?
Write your answer below
Warning: You have not logged in. You cannot answer.

Finding a file

Find (using absolute pathnames) all files whose name is index.html from the directory /usr/share/doc/ and all its subdirectories, by using the command find. Search only files, explicitly. Write down the command line:

Warning: You have not logged in. You cannot answer.

Manipulating files and folders

Creating directories 1

Change to your home directory with the command cd ~. Create a new directory with the name itl. Write down the command you used:
Write your answer below
Warning: You have not logged in. You cannot answer.

Creating directories 2

Check that you are in the directory itl with the command pwd. Now create the following subdirectories with a single command (exactly in the following order): dir1 , dir2 , dir2/subdir1 and dir2/subdir2. What command did you use?
Write your answer below
Warning: You have not logged in. You cannot answer.

Directory listing 1

Change to the directory itl you created. Show the directory listing with the command ls. After that show the directory listing with the command ls -a. What is the difference between the listings?
Warning: You have not logged in. You cannot answer.

Directory listing 2

Change to the directory dir2. Show the directory listing with the command ls. After that show the directory listing with the command ls -l. What is the difference between the listings?
Warning: You have not logged in. You cannot answer.

Moving a directory

Check that you are in the directory itl with the command pwd. If not, change to the directory itl. Now move the directory dir2/subdir1 to be a subdirectory in dir1. What command did you use?
Write your answer below
Warning: You have not logged in. You cannot answer.

Renaming a directory

Move to the directory dir2 by using the command cd dir2. Change the name of the subdirectory subdir2 to be subdir1. What command did you use?

Warning: You have not logged in. You cannot answer.

Looking at the contents of a file

The contents of a (text) file can be looked at with at least cat, less and more. Use one of these to look inside the file /etc/passwd. What is the login shell used by the user root (the last word on the line)?

Warning: You have not logged in. You cannot answer.

Finding text from a file

Use the command grep to find information about the user nobody from the file /etc/passwd. Hint: if the terminal does not seem to respond, press Ctrl-C. Write down the command you used:

Warning: You have not logged in. You cannot answer.

Copying a file

Make sure you are in the directory itl. Copy the file /etc/passwd to the current working directory. What command did you use?

Warning: You have not logged in. You cannot answer.

Removing a file

Remove the passwd file you just copied to the directory. What command did you use?

Warning: You have not logged in. You cannot answer.

Removing directories

Check with the command pwd that you are in the directory itl. If you are not, change to that directory. Now remove the directory dir1 by using the command rm and a suitable option. Write down the command you used:

Warning: You have not logged in. You cannot answer.

Creating a file

Make sure you are in the directory itl by using the command pwd, and change to the directory if you are not in it. Now, create an empty file named itl.txt without using any text editor.

Warning: You have not logged in. You cannot answer.

Editing a file

Edit the file itl.txt with the nano editor and add some content to the file. What keyboard combination do you use to save the file without leaving the editor?
Warning: You have not logged in. You cannot answer.

Renaming a file

Make sure you are in the directory itl. Rename the file itl.txt to introduction.txt. Write down the command you used.

Warning: You have not logged in. You cannot answer.

Moving a file

Make sure you are in the directory itl. Move the file you just renamed (introduction.txt) to your home directory by using relative path names. Write down the command you used:

Warning: You have not logged in. You cannot answer.

I/O Redirection

Redirecting output to a file

The output of a command line program can be redirected to a file, for example for processing or later inspection. Redirecting is done with the greater-than character ( > ). Make sure you are in the itl directory and redirect the output of the command ls -la to a file called output.txt. Write down the command you used:

Warning: You have not logged in. You cannot answer.

Reading the input from a file

You can also read programming inputs from files instead of the keyboard by using the lesser than sign (<). Use the command wc -l to find out the number of lines in /etc/passwd. Which command did you use? Note: the output should only contain a number.

Warning: You have not logged in. You cannot answer.

Piping

The output of a program can be redirected to the input of another program with the pipe character ( | ). Run the command getent passwd which outputs all usernames in the system (you can take a look!) and redirect the output to the input of the command grep root. You should get just one line of output. What is the number that is located twice on the line?

Warning: You have not logged in. You cannot answer.

Permissions

File permissions 1

What does it mean, when a file has execute permissions?
Warning: You have not logged in. You cannot answer.

File permissions 2

Make sure you are in the directory itl. The permissions of output.txt should be the following: -rw-------. Change the permissions so that group has read permission. What command did you use?

Warning: You have not logged in. You cannot answer.

Directory permissions 1

Make sure you're in the itl folder. Create the directory dir1. Then grant it the following permissions: user can only execute, group can only write and others can only read. Write down the command you used. In this exercise, give the permissions with letters, not numbers, and in the order given.

Warning: You have not logged in. You cannot answer.

Directory permissions 2

Give the directory dir1 recursively (i.e. the directory and all subdirectories and files within that directory) the following permissions with just one command: user has all the permissions, group has only execute permission, others have only execute permission. Write down the command you used. In this exercise, give the permissions with letters, not numbers, and in the order given.

Warning: You have not logged in. You cannot answer.

Changing the owner of a file

Try to change the owner of the file output.txt to user sysadm with the command chown sysadm output.txt. The command fails. Why?
Warning: You have not logged in. You cannot answer.

Process Management

Process ID

What do you use process ID's for?
Warning: You have not logged in. You cannot answer.

Process list

The command ps aux shows you all the processes in the system. Which process runs with process ID (PID) 1? You can use piping and head command to check the first line of the process list.

Warning: You have not logged in. You cannot answer.

Listing my processes

Which of the following commands does not show you your own processes? You can try all of them by changing the word USERNAME to be your own username.
Warning: You have not logged in. You cannot answer.

Killing a process

Execute the command grep FOOBAR. Nothing happens. Start a new terminal window and find the process ID of the stuck process. How do you kill the process? Write down the command you used to kill the process.

Warning: You have not logged in. You cannot answer.

Killing a process by name

Assume that a process called thunderbird is running with your user account. You want to kill it without using a process ID. What command do you use?

Warning: You have not logged in. You cannot answer.

Remote use from the terminal

Connecting with SSH

Assume that you have account itl on the computer foo.bar.com. How do you connect with SSH to that account to that computer?

Warning: You have not logged in. You cannot answer.
?