0% found this document useful (0 votes)
33 views

Module 2b: Ourne Gain Ell

This document provides an introduction to BASH and several common Linux commands and tools including cd, mkdir, ls, grep, nano, chmod, and file permissions. The key points covered are: - Using absolute and relative paths with cd, ls and mkdir - Understanding file permissions via the chmod command - Using grep to search for patterns in files - Counting search results with grep and wc - Editing files using the nano text editor

Uploaded by

Alhadi Datu-Oto
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Module 2b: Ourne Gain Ell

This document provides an introduction to BASH and several common Linux commands and tools including cd, mkdir, ls, grep, nano, chmod, and file permissions. The key points covered are: - Using absolute and relative paths with cd, ls and mkdir - Understanding file permissions via the chmod command - Using grep to search for patterns in files - Counting search results with grep and wc - Editing files using the nano text editor

Uploaded by

Alhadi Datu-Oto
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Module 2b

BASH ( Bourne Again SHell )

1
Learning Objectives

● After completing this module,


participants will be able:

- Manipulate files using built-in tools.

2
Absolute & Relative Path

● Typing cd without an argument, the


shell will sent you to your home
directory.

/home/davey

● /home/davey is also called an absolute


path.

3
Absolute & Relative Path

● Assuming you are in your HOME. Lets


populate some folders inside your
home.
mkdir -pv folder1/folder/2/folder3

● The absolute path of folder1 is


/home/davey/folder1

4
Absolute & Relative Path

● Typing.
ls /home/davey/folder1
ls folder1

● The result will be the same because


folder1 is in your relative path

5
Absolute & Relative Path

● Typing.
cd /home/davey/folder1/folder2

● You are now inside folder2. Folder1


and folder3 will now be in your
relative path.

6
Absolute & Relative Path

● The easy way to traverse directories is


to use absolute path.
● It is also the most tedious way of
traversing directories.
● Consider this kind of absolute path.

/home/dummy/somedummydir/another
dummydir/insideaotherdummydir

7
Absolute & Relative Path

● The fast way to traverse directories is


to use relative path.
● Without practice, it is also the most
confusing way.

/home/dummy/somedummydir/another
dummydir/insideaotherdummydir

8
Absolute & Relative Path

● Consider again this directories.


Assuming you are inside
anotherdummydir.

/home/dummy/somedummydir/another
dummydir/insideaotherdummydir

9
Absolute & Relative Path

● To go to somedummydir using
absolute path, you type.

cd /home/dummy/somedummydir/

10
Absolute & Relative Path

● Using relative path, you type only.

cd ../

11
./ and ../ and ../../ and ../../../

./ meaning, here in this very path.


../ one path or folder higher.
../../ two folder higher.
../../../ three folder higher.

12
Permissions and ownership

echo “12345” > apracticefile


ls -lh apracticefile

-rw-r--r-- 1 davey davey 6 Jun 11 16:49 apracticefile


----------- ------- -------- ------------------- ----------------

permission owner group creation time filename

ownership

13
Permissions and ownership

● Permission ● Ownership

read – r (4) user – u


write – w (2) group – g
execute – x (1) other - o

14
-rw-r--r-- ( The bits)

-rw-r--r--
4 2 0400400
--------- ------- -------
6 4 4
owner group other

15
-rw-r--r-- ( The bits)

● Meaning the owner, group,and others


are allowed to read and write (666).

16
-rw-r--r-- ( The bits)

● Only the is allowed to read and write


(600).

17
-rw-r--r-- ( The bits)

● Only the owner is allwed to read and


write, the rest are allowed to read
only (644).

18
-rw-r--r-- ( The bits)

● No one is allowed to read or write


(000).

19
-rw-r--r-- ( The bits)

● Will try the kill binary program (751).

20
Setting permission

● Lets create a file w/ content and view


it.
echo “abc123” > file1
echo “321cba” >> file1
cat file1

21
Setting permission

● Changing the permission and viewing


it.
chmod 400 file1
echo “def123” >> file1

chmod 600 file1


echo “def123” >> file1

22
Setting permission

● Lets try to prevent ourself from


viewing and writing to our file.
chmod 000 file1
echo “def123” >> file1
cat file1
more file1

23
grep

● Global Regular Expression Print

● A utility that searches a certain


PATTERN of string based from a
criteria

● We will only use regular pattern for


this class.

24
grep

● Preparing a file for practice.

awk '{print $3,$4,$5,$6,$7,$8,$9}' archiveEXC06.txt >


archive7.txt

● The command above will never be a part of our subject.

25
grep

● View the content of the file.


cat archive7.txt

● Probably, you new already knew the


-n option of cat.
cat -n archive7.txt
cat -n archive7.txt > archive8.txt

26
grep

● Lets grep something


grep 41m archive7.txt
grep -i 41m archive7.txt

● How many tmg files that has a 41Mb


file size?

27
grep with count

● How many tmg files that has a 41Mb


file size?

grep -i 41m -c archive7.txt


grep -i 41m archive7.txt | wc -l

● wc, another tool, meaning word count.

28
grep with count

● How many tmg files that has a 41Mb


file size that was created only in the
month of June?

grep -i 41m archive7.txt | grep -i jun

29
Nano ( The Editor )

● nano screen

30
Nano ( The Editor )

31
Nano ( The Editor )

● Try editing archive7.txt

nano archive7.txt

32
Question(s)

“Minna Ashita no test ganbatte”

33

You might also like