Section 3
Section 3
System
PRESENTED BY SALMA KISHK
Outline
Review
permissions
piping and redirection
String Processing
Users type
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
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
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 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
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
4r u rw = 4+2 = 6
2w g wx = 2+1 = 3
1x ox=1
444
r-- r-- r--
can’t edit
Default Permissions
The umask command sets the default permissions for
files and directories
output list of al
l files recursively
Let’s take a look at what this output means. The first line of the diff output
will contain:
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.
A*txt Any file that begins with the letter ‘A’ and ends with a txt
Any file that begins with either ‘a’ or ‘b’ or ‘c’ and ending with any
[abc]*
number of characters.
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
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.