Linux-Lab2-en
Linux-Lab2-en
Linux-Lab2-en
: Electricity - Electronics
Faculty of Engineering 3rd Year – 5th Semester
Branch I Lab : Linux
Num. 2: More on files
I- Hidden files :
It should be noted first that in a Linux partition the system manipulates everything as files, even
directories are considered "Directory type" files. When we talk about hidden files, this covers directories
as well.
A file is considered hidden by the system when the first character of its name is simply a dot ".", For
example ".my_file".
In general, we hide files make them invisible during normal operations, this is done more particularly
for critical files in order to avoid human deletion errors, for example: In this case, the "ls" command
does not display hidden files without adding the –a option.
II- Vi Editor :
"vi" is a text editor, its name comes from the word "Visual Instrument ”,“ vi ”works in two modes:
command mode where you can control the text file, and insert mode where you can edit the content of
the text file. The esc (Esc) key is used to switch from insert mode to command mode.
b- Basic commands for inputting text : (These commands lead directly to edit mode)
"a" to Append to the right of the cursor
"i" to Insert text to the left of the cursor
"o" to insert a new empty line below the cursor
"O" to insert a new empty line above the cursor
Enter insert an end of line
- Substitution :
:s/ceci/cela/options substitue la première occurrence de ceci par cela dans la ligne courante,
l'option g substitue toutes les occurrences dans la ligne courante ;
l'option c demande de confirmer la substitution.
:3,9s/ceci/cela remplace dans les lignes 3 à 9 la première occurrence de ceci par cela.
:%s/ceci/cela remplace dans tout le fichier la première occurrence de ceci par cela
:%s/ceci/cela/g remplace dans tout le fichier toutes les occurrences de ceci par cela
a- Create, edit and save the following text file as it is (name it "notes") with vi :
M1 M2 M3 M4 M5
Salim Salem 60 87 91 75 67
Nader Fawzi 73 45 88 90 78
Nabil Harb 81 72 68 96 55
Salwa Halabi 70 67 85 85 61
Page 2/3
III- Search a text file:
The command "grep" allows looking for a string in a text file.
e.g. grep Nabil notes
symbolic expressions can be used to compose criteria for the search:
[….] range of allowed characters (use - to consider a range or , to consider a list)
[^...] range of forbidden characters
e.g. : grep 9[0-9] notes gives the lines where the grades in the file notes >= 90.
Lab :
Compose and execute the commands capable to:
a- Extract only the first names and last names of students having their grades less than 60
b- Repeat (a) with the output displayed on the screen sorted alphabetically (use the command "sort")
c- Repeat (b) with saving the result in a text file named « failures »
Page 3/3