Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Linux:

Linux is:
1- Open Source: Linux is distributed under an open-source license,
which means that its source code is freely available to the public.
This allows anyone to view, modify, and distribute their versions
of the operating system.
2- Multitasking and Multiuser: Linux supports multitasking and
multiuser capabilities, allowing multiple processes and users to
run simultaneously on the same system.
3- Stability and Reliability: Linux is known for its stability and
reliability. It is often used in critical environments, such as servers,
where uptime is crucial.
4- Performance: Linux is designed to be efficient and can run on a
wide range of hardware, from embedded systems and personal
computers to servers and supercomputers.
5- Networking: Linux has robust networking capabilities, making it
widely used for networking-related tasks. Many network devices,
servers, and routers run Linux.
Linux is used in a variety of a applications, ranging from personal
computers and servers to embedded systems and mobile devices. It has
become a popular choice for web servers, cloud computing, and
enterprise environments due to its stability, security and flexibility.
 Linux commands to use:
Navigation and File Management:
 Ls : list files and directories
 Cd : change directory
 Pwd : print working directory
 Cp : copy files or directories
 Mv : move or rename files or directories
 Rm : remove files or directories
 Mkdir : create a new directory
 Rmdir : remove an empty directory
File Viewing and Editing:
 Cat : display the content of a file
 Nano or Vim : text editors
 Less or more : view file content page by page
 Head : display the beginning of a file
 Tail : display the end of a file
System Information:
 Uname : display system information
 Df : display disc space usage
 Free : display free and used memory
 Top or htop : monitor system precesses
Package management:
Debian/Ubuntu:
 Apt: Advanced package tool
 Dpkg: Debian package management system
Red Hat/CentOS:
 Yum: Yellowdog updater, modifier
 Rpm: Red hat package manager
Network Commands:
 Ifconfig or ip: Display network configuration
 Ping: Test network connectivity
 Traceroute or tracepath: Trace the route to a host
 Netstart: Display network connections and routing tables
User management:
 Passwd: Change user password
 Useradd: Add a new user
 Userdel: delete a user
 Su or sudo: switch user or execute commands with superuser
privileges
Process management:
 Ps: display information about processes
 Kill: terminate a process
 Pkill: send a signal to a process based on its name
Archiving and compression:
 Tar: archive files
 Gzip, gunzip, bzip2, unzip: compress and decompress files
System control:
 Reboot: restart the system
 Shutdown: shut down the system
 Systemct1: control system services
These commands cover a broad range of tasks and are fundamental for
interacting with a Linux system. To get more details in Linux, we use the
“man” command followed by the command name: “man ls”, “map cp”.
Nano and Gedit:
Nano and Gedit are two text editors commonly used on Linux systems.
They provide a user-friendly interface for editing text files in the files in
the terminal or in a graphical environment, respectively.
 Nano Command:
Nano is a simple and straightforward text editor that runs in the
terminal. It’s especially useful for users who are not familiar with more
advanced text editors like Vim or Emarcs.
To edit file using nano, this is its main syntax:
nano filename
This command opens the specified file in the nano editor. We can then
make changes to the file and nano provides on-screen instructions for
saving and exiting.
 Gedit Command:
Gedit is a graphical text editor and is part of the GNOME desktop
environment. It provides a more user-friendly interface compare to
nano and is often used in graphical environments.
To open a file using gedit:
Gedit filename
This command opens the specified file in the gedit editor. It opens in a
new window with a graphical user interface, allowing you to edit the
file using menus and buttons.
Nano is commonly used in terminal-based environments, while gedit is
often preferred in graphical desktop environments.
Shell in Linux:
To open the shell in Linux, we use the command Gedit or Nano.
These are the common used commands used in the script shell:
 Shebang:
The shebang line at the beginning of the script specifies the interpreter
to be used. For bash scripts, it’s commonly:
#!/bin/bash

 Variables:
Variables are used to store data. They are declared and assigned values
using the following syntax:
Variable_name=value
Ex:
name=”mo7sen”
 User Input:
Reading input from the user is often done using the ‘read’ command:
Read –p “Enter your name: “ username
 Conditionals:
Conditional statements are used for decision-making in scripts. The ‘if’,
‘else’, and ‘fi’ keywords are commonly used:
If [ condition ]; then
# commands
Else
#commands
Fi
 Loops:
Loops are used for repetitive tasks. ‘for’ and ‘while’ loops are common:
For item in list; do
#commands
done
-------------------------------
while [condition]; do
#commands
Done
 Functions:
Functions allow you to group code into reusable blocks:
Function_name() {
#commands
}
#call the function
Function_name
 Commands Substitution:
Command substitution allows you to capture the output of a command
and store it in a variable:
Result=$(command)
 File Operations:
Creating file: touch filename
Copying file: cp source_file destination
Moving/renaming file : mv old_name new_name
Removing file: rm filename
 Text processing:
Grep(search):
grep pattern filename
Awk(Text processing):
awk ‘{print $1}’ filename
 Comments:
Comments are to provide explanation within the script .
# This is a comment
-----------------------------------------------------------------------------------------------
Exos:
Ecrire un script shell SOMME qui calcule et affiche la some des entiers
de 1 a 100.
Voici un example de script shell qui calcule et affiche la somme des
entiers de 1 a 100 :
# !/bin/bash
# Initialise la variable de somme
somme=0
#Boucle de 1 a 100
for ((i=1 ; i<=100 ; i++)) ; do
#ajouter la valeur de l’interation a la somme
somme=$((somme + i))
done
#afficher la somme
echo ‘’ La somme des entiers de 1 a 100 est : $somme’’
Voici comment vous pouvez utiliser ce script :
1- Ouvrez un editeur de texte (comme ‘nano’ ou ‘gedit’)
2- Copiez et coller le script ci-dessus dans l’editeur
3- Enregistrez le fichier avec un nom, par example,’somme.sh’
4- Ouvrez un terminal dans le repertoire ou vous avez enregistre le
script
5- Rendez le script executable avec la commande : chmod +x
somme.sh
6- Executez le script : ./somme.sh
Le script va calculer la somme des entiers de 1 a 100 et afficher le
resultat dans le terminal.

 Pipe :
Pipe in Linux is a mechanism that allows the output of one command to
be used as the input for another command. The symbol for using pipe is
“|” the vertical bar.
Basic example:
Command1 | command2
This takes the output of ‘command1’ and uses it as the input for
‘comand2’. The data is passed between the commands through the
pipe (‘|’) without the need for temporary files.
Example:
Ls | xargs wx –l
In this example:
 Ls lists the files in the current directory
 Xargs takes the output of ls and passes it as arguments to the next
command
 Wc –l counts the number of lines for each file
-------------------------------------------------
 Grep:
Grep is a powerful command-line utility in Linux used for searching text
patterns in files. It name stands for “Global Regular Expression Print.” It
searches for a specified pattern in a file or input stream and outputs the
lines containing the pattern.
Basic Example:
Grep pattern file
This command searches for the specified ‘pattern’ in the given ‘file’ and
prints all lines containing the pattern.
 What’s a “pattern” in Linux:
In Linux, when we talk about a “pattern”, we are often referring to a
sequence of characters specified for searching using commands like
‘grep’ or ‘find’. The pattern is typically defined using regular
expressions, which are powerful and flexible ways to describe text
patterns.
1- Literal Pattern:
The simplest pattern is a literal string. For example, to find the word
”example” in a file:
grep “example” filename.txt
2- Wildcard Characters:
 ‘.’(dot): Matches any single character
 ‘*’(asterisk): Matches zero or more occurrences of the preceding
character
 ‘+’(plus): Matches one or more occurrences of the preceding
character
 ‘?’(question mark): Matches zero or one occurrence of the
preceding character
grep “a.*b” filename.txt

You might also like