Nothing Special   »   [go: up one dir, main page]

Objectives:: Lab1: Reviewing Command Line Basics

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI

3A46

Lab1: Reviewing Command Line Basics

Objectives:
The main objectives of this first lab are:

 Remember the SHELL basic commands.


 Learn basic Unix skills in navigating the filesystem and managing files and
directories. You will build upon these skills for the remainder of the course.

Part 1: Academic Questions


1. What is an operating system? Explain its features.

Response: An operating system (OS) is the interface between the computer user and the
computer hardware. An operating system is a software that performs all basic tasks such as
file management, memory management, process management, processing input and output,
and controlling peripheral devices (such as disk drives and printers).

 Features: 1.Core kernel: responsible for managing resources

2. Command interpreter: translates the commands entered by the user

3. File system: responsible for managing files

2. What is the difference between Unix and Linux ?


Response:

Unix Linux
It is a complete OS It’s kernel, it is similar to the Unix kernel
It is paid and proprietary system It is Free
It is refers to the original operating system It is refers to the kernel of the GNU/Linux
developed by AT&T. operating system.
System-V Unix and derivatives like IBM- GNU/Linux and derivates like Debian and
AIX and HP-UX; Berkeley Unix and Fedora.
derivatives like FreeBSD and macOS.

1
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

3. What are the basic elements or components of Linux?

Response: Core Kernel

Shell

File system

4. What is CLI and GUI?

Response:

CLI: Command-line interface: textual GUI: Graphic-user-interface: ergonomic


terminal and easy to use interface, designed to make
it easier for the user

5. What is Linux Shell? What types of Shells are there in Linux?

Response: Linux shell is responsible for the control management, and execution of
processes, and to ensure proper utilization of system resources. It is a program that acts as an
interface between a user and the kernel.

6. What is the minimum number of disk partitions required to install Linux? Quote them
and give the role of each?

Response: We have in general 4 primary partitions and 1 extended partition, but in


minimum we can have at least 2 partitions: the root partition (denoted as /, its role is to boot,
restore, recover, and/or repair the system) and the swap partition (its role is to substitute
disk space for RAM memory when real RAM fills up and more space is needed)

7. Unpack and explain each prompt field


a. Fields 1
b. Fields 2
c. Fields 3
d. Fields 4
8. What is the difference between a single user and a super user (root)?

Response:

2
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

SingleUser: Single users are the users created by the root or another user with sudo
privileges. Usually, a normal user has a real login shell and a home directory. They have a
limited access and permissions

SuperUser(root): is used to make system changes and can override user file protection.
root has unlimited powers, and can do anything on system hence the term superuser is
used.

9. Which are the Linux Directory Commands?

Response:

 pwd Command : The pwd command is used to display the location of the current
working directory.
 mkdir Command : The mkdir command is used to create a new directory under any
directory.
 rmdir Command : The rmdir command is used to delete a directory.

  ls Command : The ls command is used to display a list of content of a directory.

 cd Command : The cd command is used to change the current directory.

 cat Command : The cat command is a multi-purpose utility in the Linux system. It can


be used to create a file, display content of the file, copy the content of one file to another
file, and more.

 m Command : The rm command is used to remove a file.

 cp Command : The cp command is used to copy a file or directory.

 mv Command : The mv command is used to move a file or a directory form one location


to another location.

 head Command : The head command is used to display the content of a file. It displays


the first 10 lines of a file.

 tail Command : The tail command is similar to the head command. The difference


between both commands is that it displays the last ten lines of the file content. It is useful
for reading the error message.

10. How to copy a file in Linux?

Response: To copy a file named file.txt to a file named file_backup.txt in the current directory:

$cp file.txt file_backup.txt

3
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

If the destination file exists, it will be overwritten. To get a confirmation prompt before
overwriting the files, use the -i option.

$cp -i file.txt file_backup.txt

11. How to write the output of a command to a file?

Response: just redirect the output to a file:

SomeCommand > SomeFile.txt


Reditrection
12. How would you delete a full directory in Linux?

Response:
rmdir command – Deletes the specified empty directories and folders in Linux.
rm command – Delete the file including sub-directories. You can delete non-empty
directories with rm command in Linux.

rmdir directory-name
rmdir [option] directory-name

13. What does each of these characters mean under GNU/Linux

Character Description
\ To escape / quote a single character;
used to quote <new line> character to
allow continuation of a shell command
on the following line
. Represents the directory you are in
.. Represents the parent directory
~ Special home directory variable
* Match any string of zero or more
characters
? To substitute a wildcard for exactly
one character (match any single
character)
[] matches any occurrence of character
enclosed in the square brackets.
| To create pipe between commands
> To redirect output for a command
>> Appends to a file or creates the file if
it doesn't exist
&& The second command will only

4
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

execute if the first command has


executed successfully

Part 2: Getting started with Linux


1. Login to the system, open the Terminal and study the following Unix/Linux using their man
pages: cat, cd, cp, ls, mv, rm, mkdir, rmdir, echo, grep, cut.

5
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

2. Execute them on the terminal


3. Display and explain the contents of the PATH and SHELL environment variables.

6
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

 To see the path right now and shell path


4. Create the following tree structure in your home directory by following the suggested
instructions:

NB: Each question must be answered in one command and the current directory must
always be your personal directory.
(a) Create two directories; named, Unix and Python in your home directory.

(b) Create two directories TP1 and TP2 in the Unix directory.

(c) Copy the two directories TP1 and TP2 to the Python directory.

(d) Create two seance1 and seance2 directories in the Unix TP1Unix directory.

7
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

(e) Create two files exo1 and exo2 files in the seance1 directory.

(f) Copy the two files exo1 and exo2 into the Python TP2 directory as .exo1 and .exo2

5. List the contents of seance1 and Python/ TP2. Your comments?

 Python/TP2 is empty car les fichiers .exo1 et .exo2 sont des fichiers cachés
6. Move into Python/TP1. Make sure you are tcdThere, and then, using a single command,
move into Unix/TP2 by specifying the relative path.

7. Return to Python/TP1, but this time, using the absolute path. Finally, return to the root of
your home directory.

8. Remove the Python TP1 directory.

9. Remove the Python TP2 directory using the rmdir command. Why did the command fail?
Remove TP2 from Python.

8
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

 TP2 is not empty, we can’t remove it with rmdir command


10. Move exo1 to TP1 and delete seance1 and seance2.

11. Rename exo1 to exercise1.

12. List the content of the ~ directory. Your comments?

13. Create an empty file named ‘toto’ in your home directory.

14. Create a symbolic link on the toto file named "lsymb", at the tmp directory level.

15. Compare the properties of toto and lsymb. What can you deduce from this?

 Lsymb have all the privelage (read write and execute), it is pointed on the root
16. If we delete the toto file, will lsymb be available? Explain.
 Yes it still available because a symbolic link is a file that points to another file; if you delete
the target file, the symbolic links will point to an inexistan file.
17. Name 3 differences between a physical and a symbolic link.

Symbolic link Physical link

9
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

Do not share the same inode with target file. Share the same inode with target file. Hard
Hence symbolic link span across file system link does not span across file system.
Can be used for files and directories Should only be used for files not directories
If target file is deleted, the link will not work If target file is deleted, the link still works

Part 3: filters and pipes


You have a text file named telephone.txt in the calendar directory in your home directory. The
file telephone.txt is actually a small address book that is used to store information about users.
Each line of this file is in the following form:

"First name : Last name : telephone number : address "

Cut -b 13-

NB:

- The fields in this file are separated by ‘:’

- The telephone number begins with 20,21,22,23,24,25,26,27,28,29

1. Create and edit the file telephone.txt.

2. How can the address book be displayed in alphabetical order of first names? Save the result
in the carnet_sort file?

3. Sort the file following reverse alphabetical order and save the result in another file named
reverse_sort.

4. Display the first three people whose first names begin with ‘F’, using the carnet_trie file.

10
Administration & Sécurité des Systèmes d’exploitation Unix Ghofrane FERCHICHI
3A46

5. Write the command that will allow you to determine how many users you have stored in
your address book.

$cat -n telephone.txt

6. Display all users ‘first names that contain any of the letters ‘a’, ‘b’, ‘c’,‘d’ or ‘e’.

11

You might also like