Introduction to Linux Lab Report 2
Introduction to Linux Lab Report 2
LAB 2
REPORT
FULL NAME : MARIA INES RAHEB
GROUP : 01
LECTURER : DR.BERRANI
LAB INSTRUCTOR : DR.BENSALEM
INTRODUCTION TO LINUX
LAB REPORT 02
1
1.File / Directory management:
First of all I would like to inform you that according to the
instructions mentioned in the lab sheet , this report is made
using LibreOffice .
2
3)Then we write three lines of text in “file1.txt” using vi and
save the file :
3
9)Finally we’ll remove dir2 :
-The required option here is ‘-r’ which is used to remove a
directory and its contents recursively .
Command ls:
1.We start by displaying the contents of /usr/local .
4
4.By default , file and directories are arranged (displayed) in
alphabetical order . The specific order may be determined
by the underlying file system or the way the file system
organizes directory entries :
5.The possible options which can be used to modify this
classification criterion :
A.Sort by modification time :
5
B.Sort by file size :
6
C.Sort by reverse order :
7
D.Sort alphabetically by file extension :
8
6.Let’s display the contents of the current directory so that
most recently modified files appear first :
9
Directory management :
1.Yes , it’s possible to make a copy of a directory and all
of its subdirectories in a single command line :
10
6.To rename a directory “dir1” to “dir2” , you can use :
$ mv dir1 dir2
If “dir2” already exists , “dir1” will be moved to “dir2” , unless
“dir2” is a file , in which case mv will return an error .
2.WILD CARDS :
The wildcard functionality , through an asterisk , allows
to simply say : $ls *.txt
The wildcard can represent a string of any length
consisting of any characters - including the empty string .
11
3. USEFUL KEYBOARD
SHORTCUTS :
12
Commentary and explanation:
1. Create two empty files “test0.txt” and “test1.txt”.
2. List the files in the current directory and redirect the
output to the file “text2.txt”.
3. Display the content of “test2.txt”.
4. List the files of the current directory with detailed files
and subdirectories and redirect the output to
“test2.txt”.
5. Display the updated content of the file “test2.txt”.
13
4)We call this operator (>) : the output redirection operator. It
manages the flow of data between commands and file :
5)Running the commands :
14
15
6)We notice that in this example we used the operator ‘>>’ to
append the output to the file instead of overwriting it.
● When using ‘>’ the file is overwritten with the new content.
● When using ‘>>’ the content is appended to the existing file.
16
Options for less command:
● q: Quit.
● Spacebar: Scroll forward.
● b: Scroll backward. /pattern: Search for a pattern.
● :n: Jump to the next file if multiple files are opened.
17
3. Let’s display the 10 first lines of the file.
18
9. Let’s count and display the number of words in
“lines13-37.txt”.
19
To sum up the output of this command:
Description: The grep command is a powerful utility available on
Unix and Linux systems for searching through text using
patterns.
Main Options:
● -c: Counts the number of lines that match the pattern.
● -n: Displays the line numbers with the matching lines
● -i: Ignores case distinctions in both the pattern and the
input files.
● -l: Lists the filenames with matching lines, without
displaying the lines.
● -v: Inverts the match, showing non-matching lines.
● -w: Select only those lines containing matches that form
whole words.
● -r / -R: Recursively searches directories for the pattern.
20
➔ ‘-A NUM “pattern” file ’: Print NUM lines of trailing
context (after the match).
3.To display the number of the line where the searched word
appears:
21
6.To display not the lines where the word appears, but the file
names: Use -l option: ‘ $ grep -l "pattern" file’.
9. To make grep only search lines where the word appears as is,
not its variants: ‘$ grep -w "pattern" file’.
22
a. Let’s find all lines starting with “a” or “A”.
e. Let’s search for all lines starting with “B”, “E” or “Q”.
23
g. Let’s find all lines that do not end with a punctuation mark
(period, comma, semicolon, colon, question mark, exclamation
point).
24
2.Let’s copy a text file whose size is greater than 10 k bytes from
your system.
-First, we look for a text file whose size >10k, then copy its
path.
25
5.Let’s compute the total size of files in this directory.
26
● After compressing the file using gzip, we will typically
notice a reduction in file size.
9.Finally, let’s decompress the resulting file, then check the
produced files and their size.
27
28