0% found this document useful (0 votes)
10 views43 pages

Section 3

Uploaded by

hodhodmohamed86
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)
10 views43 pages

Section 3

Uploaded by

hodhodmohamed86
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/ 43

Operating

System
PRESENTED BY SALMA KISHK
Outline

Review
permissions
piping and redirection
String Processing
Users type

The root user account The service account


id : 0 The regular user account id : 0<id<1000
id : >= 1000

A service
in Linux is a program or a set of programs that run in the
background, providing various functions to the system. Services are
started automatically when the system boots up and continue
running until the system is shut down(network manager).
File system for linux

browse gui of directories

nautilus
open certain directory on Files or using the Ubuntu File Manager.
commands
adduser/ useradd
deluser
su
passwd user
pwd
cd [~, ~user, path]
mkdir, cp, rmdir
touch, cp, rm
mv (-i ask before overwrite)
cat, more, tail, head
nano, gedit
Permissions

user owner group owner


Permissions con’t

chown (change file ownership)

chown new_user_name:new_group_name file_name


Permissions con’t
Example
create user with your name and password 1234 then
create file with name file.txt, then change ownership
to default user
Permissions con’t
Permissions are assigned to
– File owner
– Members of the group the file assigned to
– All other users

Determining Permissions
Permissions con’t
we use 10 digit for each file
1. first digit file type (d, -, l)
2. Permissions
– r: read
– w: write
– x: execute
for owner, group, and other

Examples
- rw- r-- r-- file
d r-- r-- r-- dir1
Permissions con’t
Permission Access for a File Access for a Directory

You can display file


You can list the directory
Read contents and copy the
contents with the ls command
file

If you also have execute access,


You can modify the file
Write you can add and delete files in
contents.
the directory.

You can execute the file You can use the cd command to
if it is an executable. You access the directory. If you also
Execute can execute a shell script have read access, you can run
if you also have read and the ls -l command on the
execute permissions directory to list contents
Changing the Permissions

chmod permission filename

Symbolic mode
• Who Octal mode
– u: Owner permissions • 4 read
– g: Group permissions • 2 write
– o: Other permissions • 1 execute
– a: all permissions

• Operator
– + Add permissions
– - Remove permissions
– = Assign permissions absolutely

• Permissions
– r: read
– w: write
– x: execute
Examples
ls -l file1
-rw-r--r-- 1 user1 staff 1319 Mar 22 14:51 file1

chmod o-r file1; ls -l file1


-rw-r----- 1 user1 staff 1319 Mar 22 14:51 file1

chmod g-r file1; ls -l file1


-rw------- 1 user1 staff 1319 Mar 22 14:51 file1

chmod a=rw file1; ls -l file1


-rw-rw-rw- 1 user1 staff 1319 Mar 22 14:51 file1

chmod 555 file1 ls -l file1


-r-xr-xr-x 1 user1 staff 1319 Mar 22 14:51 file1
task
create file.txt and then change the permissions to give
owner read and write permissions and for group write and
execute and execute only for the others (using chmod in 2
different ways)
task
create file.txt and then change the permissions to give
owner read and write permissions and for group write and
execute and execute only for the others (using chmod in 2
different ways)

chmod u-x,g+x,g-r,o+x,o-r file1


chmod u=rw,g=wx,o=x file1

4r u rw = 4+2 = 6
2w g wx = 2+1 = 3
1x ox=1

chmod 631 file1


task
Create a file with permission 444. Try to edit in it and
to remove it? Note what
happened.
task
Create a file with permission 444. Try to edit in it and
to remove it? Note what
happened.

444
r-- r-- r--

touch file.txt or umask 333


chmod 444 touch file.txt

The rm command prompts for a confirmation, the


command is successful upon confirmation

can’t edit
Default Permissions
The umask command sets the default permissions for
files and directories

777 - 775 = 002

777 - 005 = 772 ---> rwx rwx -w-


Redirection
Redirection con’t
Command > fname (overwrite)
Command >> fname (append)

1>> redirect output


2>> redirect error
Examples

find / -name passwd 2> errs

find / -name passwd 2> errs > results

ls –l /etc >> findresult

echo hello every one again ^_^ >> file1.txt

cat <<end>> file1.txt


pipe redirection
pipe redirection con’t
ls -lR / | more

ls -lR / >> result.txt + more < result.txt


pipe redirection con’t
ls –lR / | tee fname | more The tee command reads
from the standard
input and writes to the
input standard output and a
file
input

output list of al
l files recursively

two output file


and std output
String Processing
The wc command displays the number of
characters, words, and lines in a specified file.

The syntax for the wc command is:


wc [option] [filename]

c Count the number of characters only


l Count the number of lines only
w Counts the number of words only
String Processing
diff stands for difference. This command is used to display the differences in the files
by comparing the files line by line. it tells us which lines in one file have is to be
changed to make the two files identical.

The syntax for the wc command is:


diff [options] File1 File2

Let’s take a look at what this output means. The first line of the diff output
will contain:

Line numbers corresponding to the first file,


A special symbol and
Line numbers corresponding to the second file.

a : add
c : change
d : delete
Example

file1 file2

output means after lines 1 in file 1 you have to add “cat” to match the second file
line number 2.
String Processing
The sort command sorts text data after accepting it from
either a file or the output of another command.

sort
filename.txt
task
get contents of / directory into file
sorted descending and then get
numbers of files into another file
task
get contents of / directory into file sorted descending
and then get numbers of files into another file
Regular expressions and wildcards
Similarities:
They have the same symbol but represent entirely different meanings.

Differences:
Regular expressions match file content; Wildcards are typically used to match file or
directory names.

Regular expressions are typically used on commands such as grep, sed, awk, and so on.

Wildcards are typically used with commands such as cp, find, mv, touch, ls, and so on.
wildcard
A wildcard in Linux means it might be a symbol or set of symbols representing
other characters. It is generally used in substituting any string or a character.

* – This wildcard represents all the characters


? – This wildcard represents a single character
[] – This wildcard represents a range of characters.
Options Description

* To list out all the files.

A* Any file that begins with the letter ‘A.’

Any file that begins with the letter ‘A’


A*txt
and ends with a txt

Any file that begins with List followed


List??
by 2 characters.

Any file that begins with either ‘a’ or ‘b’


[abc]* or ‘c’ and ending with any number of
characters.
Examples
Options Description

* To list out all the files.

A* Any file that begins with the letter ‘A.’

A*txt Any file that begins with the letter ‘A’ and ends with a txt

List?? Any file that begins with List followed by 2 characters.

Any file that begins with either ‘a’ or ‘b’ or ‘c’ and ending with any
[abc]*
number of characters.

[[:upper:]] Any file that begins with an uppercase letter

[![:digit:]]* Any file that does not begin with a numeral

Any file that begins from a range of a-d and followed by exactly 1
[a-d]?
character.

Any file that begins with the letter ‘A’ followed by exactly two
A??f
characters and ending with ‘f’.
Examples
wildcards Example
1. List all .log files that begin with the letter a or b.

2. List all files that have exactly 4 characters in their name (before .txt he extension).

3. Copy all files that start with doc and end with a number (0-9) in their name.
Regular expressions
Grep
Displays the lines of its input that match a
pattern given as an argument

grep options regular-expression filename(s)

I gnore case sensitive


n Precedes each line with relative line number in the file
v Inverse the search
c Counts the line that contains the pattern
w Search for the expression as a complete word
Example
Using . (Dot): The dot metacharacter matches any character except a newline. For
example, the command grep 'c.t' file.txt would match lines containing "cat", "cot", "cut",
and so on in the file.txt.

Using ^ (Caret): The caret metacharacter is used to match the beginning of a line. For
example, the command grep '^hello' file.txt would match lines that start with the word
"hello" in the file.txt.

Using $ (Dollar sign): The dollar sign metacharacter is used to match the end of a line.
For example, the command grep 'world$' file.txt would match lines that end with the word
"world" in the file.txt.

Using * (Asterisk): The asterisk metacharacter is used to match zero or more occurrences
of the preceding character or group. For example, the command grep 'ab' file.txt would
match lines containing "a", "ab", "abb", "abbb", and so on in the file.txt.
Regular expressions examples
1. Find all lines in a file that contain a date in the format YYYY-MM-DD.

2. get all regular user in /etc/passwd


Task
List the user commands and redirect the output to
/tmp/commands.list

Count the number of user commands

Get all the users names whose first character in their


login is ‘g’.
Task
List the user commands and redirect the output to
/tmp/commands.list
Count the number of user commands

Get all the users names whose first character in


their login is ‘g’.
Resources
1- diff
https://www.geeksforgeeks.org/list-all-available-commands-and-aliases-in-linux/
2- ls & wildcards
https://www.educba.com/linux-wildcards/
3-grep
https://www.geeksforgeeks.org/grep-command-in-unixlinux/
https://www.hostinger.com/tutorials/grep-command-in-linux-useful-examples/
4- regular expression
https://www.scaler.com/topics/regular-expression-in-linux/
https://regex101.com/
Any questions ?

You might also like