Linux Shell TP Eng
Linux Shell TP Eng
INTRODUCTION:
What is a shell? It is the system interface, it allows the user to communicate with the operating
system. We use a shell program to access the shell. There are several shell, sh is the first to
appear under Unix, then the “Bourne Again Shell” bash which we can define sh 2.0. The bash is an
improved version of sh, available and installed by default on macOS and Linux operating systems.
There are also others shell program ksh “Korn Shell”, csh “C shell”, tcsh “Tenex C shell” and zch
“Z shell”.
Shell programming is a mini programming language fully integrated in Linux that does not require
any compiler. The shell allows us to write scripts, which are programs for automating our tasks. It
is a system command language.
Part1: Basis
NB: In this class, we will work exclusively with bash.
The « bash » program is located in « /bin/bash ». It is possible to start the shell program
graphicaly in “programs” or with the shortcut « ctrl+alt+T ».
Now, let’s go
1. Get start with the system update « apt-get update ». The “Advanced Packaging
Tool” apt manager keeps your distribution and installed packages up to date.
2. Get the kernel version with « uname –r »
3. The command « man » is used as helper, to get information on all system
commands. Use it to get more informations on the following « ls », « ls–l », « ls–
al ».
4. Environment variables are a way to influence the behavior of software on your
system.
a. What information contains the variables « PATH », « PWD » et « LANG ». Try
with « echo $variable»
b. Can you describe each variable?
5. Create directory with mkdir « cours_scripting »
6. Moves Inside with the command cd « change directory »
Epita 2023 - 2024
File creation
7. We will learn how to create text files, with nano. Nano is a Linux built-in text
editor.
a. Create two files (bash.txt, powershell.txt) with nano, nano « filename ». The
add content.
b. Create an hidden file as third file : touch « .filename »
c. Can you describe the output of the following commands?
i. « ls »,
ii. « ls–l »
iii. « ls–al »
d. Use the redirection command « > » / « >> » to merge bast.txt and
powershel.txt content in a third file bash_powershell.txt
9. The command copy « source » « destination » », is used to copy a file from one
directory to another
a. Create a directory « cpy » in the current directory
b. Copy the file bash_powershell.txt to the new created directory
c. Copy the file bash_powershell.txt to the new created directory assigning it
new names bsh_pw.txt, bsh.dat, pw.dat,
d. Copy the file /var/syslog in the current directory
e. Create the new directories /class , /class/scripting, /session/bash
f. Copy the directory session in class, « cp –R »
g. Copy the session directory to class giving it a new name, « cp –R »
h. Move all .dat file to /class/scripting « mv *.dat »
10. The pipe command | allows the output of one command to be redirected as input
to another. The grep command searches for a string of characters in a file.
Epita 2023 - 2024
11. The "find" command is used to search for files in a mentioned directory.
a. Move to the root « / » and do
i. « find –n ethernet.h/dhclient » for find location of the directory
« ethernet.h » and the file « dhclient ».
b. Get the number of lines in the file using the command « wc ».
c. Find the authentication log file “auth.log” in the same way and list the
contents and show the number of lines
12. The "locate" command is a command used to find a file in the file system without
being at the root.
a. locate « ethernet.h »
13. The rm command allows you to delete a file and rm –r a directory and all its
contents
a. rm bash_powershell.txt
b. rm – r /cours/scripting
Part 2 : Exercises
Describe the output of the following commands?
• ls /sbin | sort > sbin.txt
root class
examples
• Try man ps command and describe the difference between ps, ps -aux, ps -e
Permission management
d. What is the output of the command « awk -F: '{ print $1}'
/etc/passwd » ?
g. Check that the new user's HOME directory has been created! if not, use
sudo useradd -m username to do so.
h. What is the output of the command : whoami ?
Screenshot