Linux Lab1 en
Linux Lab1 en
: Electricity - Electronics
Faculty of Engineering 3rd Year – 5th Semester
Branch I Lab: Linux
Num. 1: First steps
I- Introduction
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.
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.
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.
Page 2/4
"root" has his home directory in / root, where "/" is the base of the primary partition on the
disk.
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.
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.
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