You are on page 1of 38

Lab3

Files Commands

T / Ebtisam ALselwi 1
Files Commands

Function
Command

file Find out what kind of file it is.

cat Display the contents of a text file on the screen

head Display the first few lines of a text file.

tail Display the last few lines of a text file.

T / Ebtisam ALselwi 2
Files Commands(con … )

Function
Command

touch Create new file.

rm Delete a file

cp Copies a file from one location to another.

mv Moves a file to a new location, or renames it.

tac Print files in reverse

(The function of this command is to display the


file from the last to the first, which is the last line
to be the first line(
T / Ebtisam ALselwi 3
Files Commands(con … )

Function
Command

wc Used to find out information about a particular file ,


Count lines, words, characters in a file. ex: wc [-w] [ -l
] [-c] filename

grep Search for a pattern in a file or program


output.

T / Ebtisam ALselwi 4
touch Command
std@ubuntu:~$ touch Ebtisam.txt

T / Ebtisam ALselwi 5
File Command
std@ubuntu:~$ file sample.txt

std@ubuntu:~$ file sample.txt


sample.txt: empty

T / Ebtisam ALselwi 6
T / Ebtisam ALselwi 7
File Command
std@ubuntu:~$ file sample.txt

std@ubuntu:~$ file sample.txt


sample.txt: ASCII text

T / Ebtisam ALselwi 8
T / Ebtisam ALselwi 9
File Command
std@ubuntu:~$ file test

std@ubuntu:~$ file test


test: directory

T / Ebtisam ALselwi 10
Cat Command
std@ubuntu:~$ cat sample.txt
sample line 1
sample line 2
sample line 3
sample line 4
sample line 5
sample line 6
sample line 7
sample line 8
sample line 9
sample line 10
sample line 11
sample line 12
sample line 13
sample line 14
sample line 15
sample line 16
sample line 17
sample line 18
sample line 19
sample line 20

T / Ebtisam ALselwi 11
Cat Command
std@ubuntu:~$ cat file1.txt

std@ubuntu:~$ cat file1.txt


line 1
line 2

T / Ebtisam ALselwi 12
T / Ebtisam ALselwi 13
Cat Command
std@ubuntu:~$ cat sample.txt sample1.txt
sample line 1
sample line 2
sample line 3
sample line 4
sample line 5
sample line 6
sample line 7 To read more than
sample line 8
one file in same time ,
sample line 9
sample line 10 and merge them on
sample line 11 the screen only
sample line 12
sample line 13
sample line 14
sample line 15
sample line 16
sample line 17
sample line 18
sample line 19
sample line 20

line 1
line 2

T / Ebtisam ALselwi 14
Cat Command
std@ubuntu:~$ cat –n sample.txt sample1.txt
1 sample line 1
2 sample line 2
3 sample line 3
4 sample line 4
5 sample line 5
6 sample line 6
7 sample line 7
8 sample line 8
To read more than
9 sample line 9 one file in same time,
10 sample line 10 with merge them on
11 sample line 11 the screen only and
12 sample line 12
13 sample line 13 number each line
14 sample line 14
15 sample line 15
16 sample line 16
17 sample line 17
18 sample line 18
19 sample line 19
20 sample line 20
21
22 line 1
23 line 2

T / Ebtisam ALselwi 15
Cat Command
std@ubuntu:~$ cat sample.txt sample1.txt
>sample2.txt

To merge more
than one file
into a new file

T / Ebtisam ALselwi 16
Cat Command
std@ubuntu:~$ cat >sample1.txt
In the name of Allah
std@ubuntu:~$
To write in a file,
with delete all the
data that was
inside it, after
finishing typing in
the file press the
Enter key, then
press on
(Ctrl + d) to save
the file.

T / Ebtisam ALselwi 17
Cat Command
std@ubuntu:~$ cat>>sample1.txt
T/ Ebtisam ALselwi

To modify inside a
file written in it
and add new data
to it while
retaining data
Previously ،press
the Enter key, then
press on
(Ctrl + d) to save
the file.

T / Ebtisam ALselwi 18
Cat Command

T / Ebtisam ALselwi 19
tac Command
std@ubuntu:~$ tac sample1.txt
sample line 20
sample line 19
sample line 18
sample line 17
sample line 16
sample line 15
sample line 14
sample line 13
sample line 12
sample line 11
sample line 10
sample line 9
sample line 8
sample line 7
sample line 6
sample line 5
sample line 4
sample line 3
sample line 2
sample line 1
std@ubuntu:~$
T / Ebtisam ALselwi 20
Head Command
std@ubuntu:~$ head sample.txt

sample line 1
sample line 2
sample line 3
sample line 4
sample line 5
sample line 6
sample line 7
sample line 8
sample line 9
sample line 10
std@ubuntu:~$

T / Ebtisam ALselwi 21
Head Command
std@ubuntu:~$ head file1.txt

line 1
line 2

T / Ebtisam ALselwi 22
tail Command
std@ubuntu:~$ tail sample.txt

sample line 13
sample line 14
sample line 15
sample line 16
sample line 17
sample line 18
sample line 19
sample line 20

T / Ebtisam ALselwi 23
tail Command
std@ubuntu:~$ tail file1.txt

line 1
line 2

T / Ebtisam ALselwi 24
touch Command
std@ubuntu:~$ touch Ebtisam.txt

T / Ebtisam ALselwi 25
touch Command
std@ubuntu:~$ touch file1.txt file2.txt

T / Ebtisam ALselwi 26
rm Command
std@ubuntu:~$ rm Ebtisam.txt

T / Ebtisam ALselwi 27
cp Command
std@ubuntu:~$ cp sample.txt test/sample.txt

T / Ebtisam ALselwi 28
cp Command
std@ubuntu:~$ cp sample.txt test/sample1.txt

T / Ebtisam ALselwi 29
mv Command = rename
std@ubuntu:~$ mv sample.txt samplenew.txt

T / Ebtisam ALselwi 30
mv Command = move
std@ubuntu:~$ mv samplenew.txt
test1/samplenew.txt

T / Ebtisam ALselwi 31
T / Ebtisam ALselwi 32
wc Command

std@ubuntu:~$ wc -l sample1.txt
21 sample1.txt Count of lines

std@ubuntu:~$ wc -w sample1.txt
60 sample1.txt count of words

std@ubuntu:~$ wc -c sample1.txt
293 sample1.txt size of file in byte

std@ubuntu:~$ wc -m sample1.txt
293 sample1.txt count of characters
std@ubuntu:~$

T / Ebtisam ALselwi 33
grep Command

std@ubuntu:~$ grep Linux sample.txt

Search for lines containing the word Linux

Linux: is a Unix-like operating system that


std@ubuntu:~$

T / Ebtisam ALselwi 34
grep Command

std@ubuntu:~$ grep –v Linux sample.txt

Search for lines that do not contain the word Linux

was designed to provide personal computer


users a free or very low-cost operating system
comparable to traditional and usually
more expensive Unix systems,
developed by Linus Torvalds.

T / Ebtisam ALselwi 35
grep Command

std@ubuntu:~$ grep ^Linux sample.txt

To search for lines beginning with the word "Linux"

Linux: is a Unix-like operating system that


std@ubuntu:~$

T / Ebtisam ALselwi 36
grep Command

std@ubuntu:~$ grep Linux $ sample.txt

To find the lines that end with the word "Linux"

operating system Linux

T / Ebtisam ALselwi 37
End ….
T / Ebtisam ALselwi 38

You might also like