0% found this document useful (0 votes)
14 views4 pages

Linux Lab1 en

Uploaded by

Georgio Karam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Linux Lab1 en

Uploaded by

Georgio Karam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lebanese University Dept.

: Electricity - Electronics
Faculty of Engineering 3rd Year – 5th Semester
Branch I Lab: Linux
Num. 1: First steps

I- Introduction

a. The System UNIX

UNIX is the name of software belonging to the category called "Operating Systems". It is
thanks to OSs that we can use computers: invoke programs, manipulate files, etc. UNIX is a
multi-user, multi-tasking operating system, which means that it allows a single-processor or
multi-processor computer to run multiple programs simultaneously by one or more users.
It has one or more command interpreters (called the "Shell") as well as a large number of
commands and many utilities (assembler, compilers for many programming languages, word
processors, electronic messaging, etc. . .). In addition, it has great portability, which means
that it is possible to implement a UNIX system on almost all hardware platforms.

b. The System Linux

Linux is a software belonging to the large family of open UNIX systems and falls under the
category of “free” software, its source code is developed by users and available to all users.
The free or commercial software available for Linux correspond to the vast majority of needs:
publishers, development tools, software for managing network services (printing, data and
applications, electronic messaging, etc.), scientific applications, office suites, graphic
interfaces, games, etc...
Linux is available in the form of “distributions” (Like Fedora, Ubuntu…). They are complete
and cohesive sets of programs that they can be used to set up a usable system. They are
available on FTP sites and on commercial DVDs.

c. Objectives of the Linux lab series

Like any OS, Linux includes the basic programs your computer needs to perform user-
requested instructions:
1) Read and write data to hard drives, external drives, or to printers;
2) Monitor the memory usage;
3) Monitor the network usage and data exchange protocols between servers and network
clients such as e-mail, the Web, FTP, …;
4) Run other programs and apps, etc.
Thus, in this set of labs, we will aim to master as much as possible the use of the Linux
system by mastering its basic commands, access and use permissions, in order then to be able
to write command routines (called Shell scripts).

Page 1/4
II- The tree structure in a Linux partition (Ext X):
A tree is often understood to mean the hierarchy of directories in a primary partition of the
operating system. Most systems derived from UNIX have more or less the same directory
hierarchy. In the following table, we list the main directories with a brief description of their
contents.

Directory Sub Directory Content


/bin /usr/bin Basic commands
/usr/local/bin Additional commands added by
administrator
/sbin /usr/sbin Administration commands
/boot Files of Linux kernel
/dev Special files of peripherals
/etc /etc/rc.d Files of configuration of the system
/etc/init.d Files of services
/home Contains the personal directories of the
users
/lib /usr/lib Library of sub programs
used for the development (API.., SDKs,..)
/mnt /mnt/cdrom Special files of external storage peripherals
/mnt/floppy as USB, DVD,…
/mnt/usb
/proc A directory dedicated for processes
/root Personal directory of the administrator
The administrator of Linux also called
root.
/tmp Temporary files used by the system
/usr Main directorty of the system
/usr/include Sub directory of Header files
/usr/share/man Sub directory of manual files (Help source)
/usr/local Installed Apps by root (the admin)
/var /var/log Directory of the variable part of the system
/var/spool as les logs of activities of the system; the
/var/spool/mail mailboxes, etc.
/var/mail

III- The basic commands:


a. The terminal and the Shell:
When the system starts up, several terminals become available to use, they are accessible by
the keys ALT Fx where x can have the value 1, 2, 3,…, only one of these terminals will
appear in a graphical form (Graphical User Interface) where we can also launch more
terminals to operate.
The terminal is used to offer the user a command interpreter interface, called "Console", we
can see the console as an input / output subsystem (keyboard / screen), and it is designated in
the file system by the logical name "con".
The interpretation of commands is done by what is called "shell", each Linux system has
several shells like sh, csh, ksh, ...). "Bash" which is an alias name of sh is adopted as the Shell
by default. The difference between the "shells" no longer concerns the basic commands that
we will see later.
Finally, it should be noted that when starting up, the terminal puts us in the personal directory
dedicated to the user, that is to say that we can work directly in our "Home directory", for
example if the user opening the terminal is "user1" then the terminal opens and executes the
operation directly in / home / user1. Only the administrator, often referred to in Unix as

Page 2/4
"root" has his home directory in / root, where "/" is the base of the primary partition on the
disk.

b. Commands of Directory Management

In any operating system based on the "Disk Operating System" disk, the set of
commands must contain a subset dedicated to manage the directories. In Linux, the following
commands are used:
i. pwd: without any arguments, display the current directory on the screen.
i. ii. mkdir (make directory): to create a new directory, e.g.: "mkdir test", where test
here will be the name of the directory crée1.
iii. rmdir (remove directory): to remove a directory, provided it is empty, e.g. "rmdir
test".
iv. cd (change directory): to change the active directory, e.g. "cd test", if "test" is a
directory accessible2 directly from the active directory. So to return to the parent directory we
can use the command "cd .." where ".." is an existing pointer in each directory and represents the
parent.
A special case of using the "cd" command with no arguments is to revert to the home
directory from any previous location.
v. ls (list): this command displays on the screen the contents of the active directory (if
this command is used without arguments), or the contents of a directory passed as an argument
as in the command: "ls test".

Lab  :
1. Execute the appropriate commands to create the following directory structure in the home
directory "ubuntu":
 /home/ubuntu/R
 /home/ubuntu/r3
 /home/ubuntu/R/R1
 /home/ubuntu/R/R2
 /home/ubuntu/R/R3
 /home/ubuntu/R/R2/F1
 /home/ubuntu/R/R2/F2
 /home/ubuntu/r/Documents
 /home/ubuntu/r/Documents/Texts

2. The command "man" (manual), it is used to browse the guide of how to use the
commands with what are called "Options". Try to discover the options of the ls command
and to focus mainly on knowing how we can display the content as a table (a real list).
3. Remove all the sub-directories already created.

c. The commands File Management :

We always think of a directory as a container for files and other directories called sub-
directories. Directories are blocks that help to organize the contents of the disk. While the
files are the data itself, texts, applications, object files, databases, configurations, images,
sounds, videos, drawings, drivers, mail,...
File management touches the most important function at the level of use of any OS.

1
The name of a directory must include its full path, but it’s also enough to use only the direct name when managing it inside its
parent directory.
2
Always, the system shows the sub-directories of the working directory.
3
Linux, like the C language is case sensitive.

Page 3/4
This first Lab cannot cover all the commands concerning the files, first we will be satisfied to
start with some basic commands. A larger set of commands will be studied and explored later
in this set of labs.

i. touch : used to create a new file without determining its genre (text, binary or other).
If the file exists, it updates the creation date of the existing file as if it was created on
the command execution date, e.g.: "touch test"
ii. cat4 : displays the content of a text file (or multiple files) on the screen: "test cat"
iii. more : displays the content of a text file page by page
iv. rm : deletes a file specified by its name, e.g.: "rm essay"
v. cp : copies a file to eventually another directory with or without changing the name of
the file, e.g.: "cp essay trial1"
vi. mv : used to change the location of a file from one directory to another, or to rename
the file even in its initial location, e.g.: "mv test Test" (change name)
Lab  :
Explore rm and find out how you can delete an entire directory with its subdirectories using this
command, for that you will need to create a directory structure with subdirectories and some even
empty files.

d. The redirection of Input/Outputs of commands :


Each command has:
 One standard input
 One standard output
 One error output

By default, the standard input is the keyboard, the standard output is the screen, and the error
output is the screen.
In fact, we can redirect the input, output, and error output of a command to text files.

i. Actually, "ls > lista" means redirect the output of the command ls towards a file to be
created and named lista, if lista already exists then the previous content will be
replaced by the result of the command ls.
ii. While that the command : "ls >> lista" will add the result of the command ls to the
content of the file lista.
iii. The symbol « < » is used to redirect the input (by default the keyboard) to another text
file, the command will read so the file instead of the keaboard. e.g. :
"more < essai" equivalent to "more essai" because more without argument reads its
input from the keyboard and then display it page by page on the terminal.
iv. Finally to redirect the error resultant of the execution of a command to a file we use
simply the symbol « 2> ».
Lab  :
1. By using simply the commands already seen, create a text file with le following content :
This is my first lab Linux
These are my first steps
On the road of systems
With free code source

2. Try to write a false command, e.g., change the current directory to another inexistent, and
then repeat the same command with error redirection to the file "Errors".

4
Cat without argument means « display the Console represented here by the keyboard», this may be applied on all the commands
having a file as argument of input.

Page 4/4

You might also like