0% found this document useful (0 votes)
27 views7 pages

Linux Shell TP Eng

This document provides an introduction to Linux shell commands and administration. It covers basics like updating the system, viewing kernel version, and using man pages. It also covers file manipulation like creation, reading, copying, searching and deletion. Directory navigation and permissions are explained as well.

Uploaded by

coucou salut
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)
27 views7 pages

Linux Shell TP Eng

This document provides an introduction to Linux shell commands and administration. It covers basics like updating the system, viewing kernel version, and using man pages. It also covers file manipulation like creation, reading, copying, searching and deletion. Directory navigation and permissions are explained as well.

Uploaded by

coucou salut
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/ 7

Epita 2023 - 2024

LINUX SHELL : Intro

Goal : Learn bash shell administration commands

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

Test files reading

8. Now, we will use cat « non_fichier » show a file content


a. cat var/syslog (show syslog content)
b. What does the following command do : less var/syslog ?
i. Can you number each line ? (man cat)
c. What does the following command do: head -n var/syslog/ ?
d. What does the following command do: tail -n var/syslog/ ?
e. What does the following command do: sort -n var/syslog/ ?

File copy and modification

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

a. So what is the output of the command « ls | grep pw » ?


b. We will now sort the result of a cat and retrieve all rows containing the
keyword «NetworkManager »
i. cat var/syslog |grep NetworkManager
c. Now try to count the number of rows returned "-c"

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 »

Deleting files and directories

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

• cat /var/log/syslog | tail


Epita 2023 - 2024

• create the following tree

root class

student adm exercises

examples

create the following files:


student: personalfile.dat,
class: class01.doc, class02.doc
adm: note.txt. commands.txt. notes.dat
exercises: exercises01.txt, exercises02.txt, exercises03.txt
examples: example01.txt, example02.txt, example03.txt, command.dat

• Try man ps command and describe the difference between ps, ps -aux, ps -e

Tree command result


Epita 2023 - 2024

Permission management

Linux allows efficient management of the rights of a user or group on a file or


directory. Below is a description of the rights
d : directory
r / 4: read permission
w / 2 : write permission
x / 1 : execution permission

The interpretation order


drwxr-xr-x ethernet
First char : file type
Next three chars : file owner rights
Next three chars: the rights related to the file owner's group
Next three chars: others rights
14. Start by listing all the users on your machine less /etc/passwd
User name.
Encrypted password (x means that the password is stored in the /etc/shadow
file).
User ID number (UID).
User’s group ID number (GID).
Full name of the user (GECOS).
User home directory.
Login shell (defaults to /bin/bash).
a. What is your User ID and Group ID?

b. How many users are there?

c. List the groups !


Epita 2023 - 2024

d. What is the output of the command « awk -F: '{ print $1}'
/etc/passwd » ?

e. groupadd is used to create a new group


f. sudo useradd is used to create a new user
i. Use – h pour voir les options
ii. Now you must to create a new user's and password,
iii. Then create a group for your new user
iv. Add you user to the new created group

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 ?

i. Use su – username to connect with the new user


j. The chmod command allows you to modify the rights of a user or group on
a file or a folder.
chown allows you to change the owner of a file and directory
chgrp allows you to change the owner group of a file or directory
i. chown bash_powershell.txt christ
ii. chmod +x bash_powershell.txt
k. Create two new users, user1 et user2
l. Create a new group new. Both users must belong to different groups
m. Create a file user1.txt, which belongs to user1 and the file user2.txt which
belongs to user2. User1.txt cannot be modified by user2 and vice versa.

Screenshot

n. Create a directory user1 inaccessible by user2 and a directory user2


inaccessible to user 1
o. What is the output of the command : grep user1 /etc/passwd ?
Epita 2023 - 2024

p. What is the output of the command : grep user2 /etc/passwd ?

You might also like