Sie sind auf Seite 1von 111

Linux Commands and Shell Scripting

Done by:- Group One

Linux Basic Commands

Shell Scripting

Basics

Loops and Conditionals

Functions

User management and File permissions


What is Linux
Linux is a free open-source operating system.
Free
Unix Like
Open Source

2
Strictly speaking, Linux is a kernel. A kernel provides
access to the computer hardware and control access
to resources
Created by Linus Torvalds.
Open source .

3
Linux distribution
A Linux distribution (often abbreviated as distro) is
an operating system made from a software
collection, which is based upon the Linux kernel and,
often, a package management system.
Linux users usually obtain their operating system by
downloading one of the Linux distributions

4
Widely used distributions
Debian
Knoppix
Linux Mint Debian Edition(LMDE)
Ubuntu(Kubuntu, Linux Mint, Trisquel, Elementary OS).

Fedora
Red Hat Enterprise Linux (RHEL)
(CentOS, Oracle Linux, Scientific Linux,
MandrivaLinux ( Mageia, PC LinuxOS, ROSA Linux,)
Open SUSE(SUSE Linux Enterprise)
Arch Linux, Gentoo, Slackware.
5
Why Linux is better than Windows
Managing File system
Virus
Update
Servers
Total cost of ownership
Sound architecture

6
Basic commands
Cat
Tac
Head
Tail
Wc
Others.

7
Cat and tac
The cat command is one of the most universal tools.
All it does is copy standard input to standard output.
$ cat filename
create flat text files.
cat > filename
Press ctlr d send end of file
Or $ cat > hot.txt <<stop - declare stop key word

The tac command is the opposite of cat command

8
head
Print the first 10 lines from a file directory
$ head filename
The head command can also display the first n lines of a
file.
$ head n filename

9
Tail
Similar to head, the tail command will display the last
ten lines of a file.
$ tail filename
You can give tail the number of lines you want to see.
$ tail -3 count.txt

10
Sort file
The sort command sorts its input line by line
By default, does alphanumeric sort on entire line
Command line options include:
f ignore uppercases
n- numeric sort
r-revers sort
k N- sort on a field N
uniq- remove duplicates from a sorted list.

11
wc
The command wc counts lines, words and characters
in its input files
Command line options include
l show only the lines
w- show only the words
c- show only the character
L- show the length of the longest files

12
Name cd
Syntax: cd [directory]
Description: The current working directory to the
directory specified by "directory".
Name: ls
Syntax: ls [options] [pathname-list]
Description: display the file name within the
directory and file name specified in the
"pathname-list"

13
Name: pwd
Syntax: pwd
Description: Displays the absolute path of the
current directory.
Name: mkdir
Syntax: mkdir [options] dirName
Description: create name is dirName subdirectory

14
Name: rmdir
Syntax: rmdir [-p] dirName Description: delete
empty directories
Name: cp
Syntax: cp [options] file1 file2 Description: Copy
the file file1 to file2.

15
Name: mv
Syntax: mv [options] source ... directory
Description: Rename the file, or the number of files
to another directory. Example: aaa renamed as
bbb:
Name: rm
Syntax: rm [options] name ...
Description: delete files and directories. Commonly
used options:-f to force delete files

16
Name: cat
Syntax: cat [options] [file-list]
Description: standard output connection, display a list of
files in the file-list file
ln:
Syntax: ln [options] existing-file new-file ln [options]
existing-file-list directory
Description: create a link named "existing-file" new-file

17
Name: chmod
Syntax: chmod [option] mode file-list
Description: read, write, or execute permissions
change or set the parameters in the file-list
Example: Add file job executable permissions
chmod + x job.sh
Syntax: chmod [option] [files]

18
Standard Input Output redirection

19
Introduction

Linux includes redirecting commands for each stream


Overwriting
> - standard output
< - standard input
2> - standard error

Commands with a single bracket overwrite the


destination's existing contents
20
Cont..
Appending
>> - standard output
<< - standard input
2>> - standard error

Commands with a double bracket do not overwrite the


destination's existing contents

21
Redirecting standard Output
> stdout
stdout can be redirected with a greater than sign. While
scanning the line, the shell will see the > sign and will
clear the file.
[paul@RHELv4u3 ~]$ echo It is cold today! > winter.txt
[paul@RHELv4u3 ~]$ cat winter.txt
It is cold today!
22
Cont..
command > file
This pattern redirects the standard output of a command to a file.
ls ~ > root_dir_contents.txt
The command above passes the contents of your system's root
directory as standard output,
and writes the output to a file named rootdircontents.txt.
It will delete any prior contents in the file, as it is a single-bracket
command.

23
Cont..
command > /dev/null
/dev/null is a special file that is used to trash any data that is
redirected to it.
It is used to discard standard output that is not needed, and
that might otherwise interfere with the functionality of a
command or a script.
Any output that is sent to /dev/null is discarded.

24
Cont..
noclobber
Erasing a file while using > can be prevented by setting the
noclobber option.
[paul@RHELv4u3 ~]$ cat winter.txIt is cold today!
[paul@RHELv4u3 ~]$ set -o noclobber
[paul@RHELv4u3 ~]$ echo It is cold today! > winter.txt
-bash: winter.txt: cannot overwrite existing file
[paul@RHELv4u3 ~]$ set +o noclobber

25
Cont..
command >> file

This is redirects the standard output of a command to a file

without overwriting the file's existing contents.


echo Written to a new file > data.txt

echo Appended to an existing file's contents >> data.txt

commands first redirects the text inputted by the user through

echo to a new file

26
Cont..
It then appends the text received by the second echo

command to the existing file, without overwriting its

contents.
Ls ~ >> data.txt

And also the above command append the results of the

command to the file.

27
Redirecting standard error
2> stderr
Redirecting stderr is done with 2>. This can be very
useful to prevent error messages from cluttering your
screen.
The screenshot below shows redirection of stdout to a
file, and stderr to /dev/null.
[paul@RHELv4u3 ~]$ mkdir > allfiles.txt 2> /dev/null
28
Cont..

2>&1
To redirect both stdout and stderr to the same file, use
2>&1.
[paul@RHELv4u3 ~]$ find / > allfiles_and_errors.txt
2>&1
[paul@RHELv4u3 ~]$

29
Cont..
command 2>> file
The pattern above redirects the standard error stream
of a command to a file without overwriting the file's
existing contents.
Mkdir '' 2>> stderr_log.txt

30
Redirecting Standard input
Many commands can accept input from a facility called
standard input
By default, standard input gets its contents from the
keyboard,
but like standard output, it can be redirected.
To redirect standard input from a file instead of the
keyboard, the "<" character is used
31
Cont
This < character used with other command like cat, pipes or |
sort etc. and the redirecting of input is works with the
combination of < and >.
Cat - concatenate files
Sort - Sorts standard input then outputs the sorted result on
standard output.
paul@deb503:~$ cat > tennis.txt << ace
> Justine Henin
> Venus Williams
> Serena Williams
> Martina Hingis
> Kim Clijsters
> ace
32
Cont
paul@deb503:~$ cat < tennis.txt > test.sh
paul@deb503:~$ cat test.sh
Justine Henin
Venus Williams
Serena Williams
Martina Hingis
Kim Clijsters

33
Pipes
A pipe is a form of redirection that is used in Linux
and other to send the output of one program to
another program for further processing.
Can run multiple commands on the same command
line.
A pipe is designated in commands by the vertical
bar character.
General syntax:
command_1 | command_2 [| command_3 . . ]

34
Examples of usage of pipe
the output of the ls command is commonly piped
to the the less (or more) command to make the
output easier to read :
ls -al | less or
ls -al | more
For other directories like /etc
ls al /etc | less

35
cont
Capture standard out put:
Example:
echo -e "orange \npeach \ncherry" | sort > fruit
the echo command sends what it follows to the
stdout,
the e option tells the computer to interpret each \n
as a new line symbol,
the pipe redirects the out put to the sort command
then redirected to the file fruit.

36
cont
Capture standard out put:
Example:
echo -e "orange \npeach \ncherry" | sort > fruit
the echo command sends what it follows to the
stdout,
the e option tells the computer to interpret each \n
as a new line symbol,
the pipe redirects the out put to the sort command
then redirected to the file fruit.

37
Other examples
ls l | grep ^- : list all files in the current directory.
ls | head | tail > myfile : list the head and tail files
and print it on myfile.
Wc l < myfile | tee newfile
dmesg | less : startup messages can conveniently
be viewed one screen full at a time.

38
Linux Shell

39
What is Linux Shell?
In Linux operating system, there is a special program
called the shell. The shell accepts human readable
commands and translates them into something the
kernel can read and process
Generally speaking the shell:
is a user program or it is an environment provided for
user interaction

40
Linux Shell. . .

is a command language interpreter that executes


commands read from the standard input device such
as keyboard or from a file
gets started when you log in or open a console
(terminal)
Several shells are available for Linux including:
BASH ( Bourne-Again Shell ) - Most common shell in
Linux, it's Open Source shell
CSH- the C shell's syntax and usage are very similar
to the C programming language

41
Linux Shell. . .
KSH (Korn SHell) - Created by David Korn at AT & T
Bell Labs. The Korn Shell also was the base for the
POSIX Shell standard specifications
etc. . .
Each shell does the same job, but each understands
different command syntax and provides different
built-in functions. Under MS-DOS, the shell name is
COMMAND.COM which is also used for the same
purpose, but it is by far not as powerful as our
Linux Shells are!
42
Linux shell. . .
Shell Prompt
There are various ways to get
shell access:
Terminal - Linux desktop
provide a GUI based login
system. Once logged in you
can gain access to a shell by
running X Terminal (XTerm),
Gnome Terminal (GTerm), or
KDE Terminal (KTerm)
application

43
How do I find Out My Current Shell
Name?
To find all of the available shells in your system, type
the following command:
cat /etc/shells
In case the shells file has more than one shell listed
under it, then it means that more than one shell is
supported by your Platform
To find out your current shell type following
command:
echo $SHELL
44
Getting Help In Linux
Most commands under Linux will come with
documentation. Use any one of the following
option to get more information about Linux
commands:
man commandName
info commandName
commandName --help

45
What is a Shell Script or shell
scripting?
A Shell script can be defined as "a series of
command(s) stored in a plain text file".
A shell script is similar to a batch file in MS-DOS, but it
is much more powerful compared to a batch file.
Each shell script consists of:
- Shell keywords, Shell commands, Linux binary
commands, Text processing utilities, Functions, and
Control flow statements

46
Why shell scripting?
Whenever you find yourself doing the same task over
and over again you should use shell scripting, i.e.
repetitive task automation.
Shell commands: The bash shell comes with two types
of commands
1. Internal commands (builtins) - part of the shell itself,
i.e. built into the shell
2. External commands - separate binaries stored in
/sbin, /usr/sbin, /usr/bin, /bin, or /usr/local/bin
directories
47
type Command

the type command can be used to find out if a


command is built in or an external binary file.
Type the following command at a shell prompt:
type -a ls
- The Sample output becomes: ls is /bin/ls to
mean it is an external command
To find out if history command is a built in or an
external command, enter: type -a history
- The sample output is: history is a shell built in

48
Starting Shell- Hello world

Open your text editor

Write required Linux commands and logic in the


file

Make the file executable

Test

Ship to production

49
Simplest of all

What is the simplest shell program?


The one who tells the computer a command

50
Hello world
#!/bin/bash #tells indicate an interpreter for execution under UNIX / Linux operating systems.

clear
echo "Hello, World!"
echo "Working with Linux scripting gets started."

51
shebang

It is called a shebang or a "bang" line.

It is nothing but the absolute path to the Bash interpreter.

It consists of a number sign and an exclamation point character (#!),


followed by the full path to the interpreter such as /bin/bash.

All scripts under Linux execute using the interpreter specified on a first
line.

Almost all bash scripts often begin with #!/bin/bash (assuming that Bash has
been installed in /bin)

This ensures that Bash will be used to interpret the script, even if it is

executed under another shell .


52
Ignoring shebang

the default is usually the /bin/sh.

Recommended that you set #!/bin/bash line.

53
Shell Comments

Use #single line comment



<<COMMENT1
this script is getting high with multi line
comments
may be we consider to learn more
COMMENT1

54
Changing permission on script

Since each shell script must have an execute


permission we can use chmod command
(change mode) is a shell command in Linux.
chmod +x script.sh #Allowing everyone to execute the script
chmod 0755 script.sh
chmod 0700 script.sh #Only allow owner to execute the script
chmod u=rwx, go= script.sh
chmod u+x script.sh
ls -l script.sh #To view the permissions, use:
chmod ug=rx script #Set the user and the group to read and execute
only
chmod ug= script.sh #Remove read and execute permission for the group
and user
55
Executing a command

./script.sh afeter setting permission

run the script directly without setting the script


execute permission:
Bash script.sh
. script.sh

56
Variables in shell

You can use variables to store data and


configuration options.

There are two types of variables


system variable and

created and maintained by Linux bash shell itself

defined in CAPITAL LETTERS

Use env or printenv to see yours
user defined variable.

Created and maintained by user.

may use any valid variable name

good practice to avoid all uppercase names

57
Rules for naming variables

Variable name must begin with alphanumeric


character or underscore character (_),
followed by one or more alphanumeric or
underscore characters.

Do not put spaces on either side of the


equal sign when assigning value to variable.

Variables names are case-sensitive, just like


filenames.

Do not use ?,* and other special characters,


to name your variable.
58
Unset variable
Use unset command to delete the variables during
program execution. It can remove both functions
and shell variables.
travel=Bus
echo $travel
unset travel
echo $travel

59
Read from keyboard

accept input from the keyboard and assign


an input value to a user defined shell variable
using read command
#!/bin/bash
read -p "Enter your name : " name
echo "Hi, $name. Let us be friends!"

60
Perform Arithmetic Operations

61
Shell Decision Making

62
If ---------fi statements

Linux Shell supports conditional statements which are used to


perform different actions based on different condition.

The if...fi statement is the fundamental control statement that


allows Shell to make decisions and execute statements
conditionally.

if [ expression ] then

Statement(s) to be executed if expression is true

fi
63
Cont

Give you attention on the spaces between braces and expression. This space is
mandatory otherwise you would get syntax error.

#!/bin/bash

a=10

b=10

if [ $a == $b ]

then

echo "a is equal to b

fi

64
The if...else...fi statement

allows Shell to execute statements in more controlled way and making


decision between two choices.

Syntax

if [ expression ]

Then

Statement(s) to be executed if expression is true

else

Statement(s) to be executed if expression is not true

fi
65
Cont

Give you attention on the spaces between braces and expression. This space is
mandatory otherwise you would get syntax error.

#!/bin/bash

a=10

b=10

if [ $a == $b ]

then

echo "a is equal to b

fi

66
Cont

Give you attention on the spaces between braces and expression. This space is
mandatory otherwise you would get syntax error.

#!/bin/bash

a=10

b=10

if [ $a == $b ]

then

echo "a is equal to b

fi

67
If elif fi

if [ expression 1 ]

then

Statement(s) to be executed if expression 1 is true

elif [ expression 2 ]

then

Statement(s) to be executed if expression 2 is true

elif [ expression 3 ]

then
68
Cont

Give you attention on the spaces between braces and expression. This space is
mandatory otherwise you would get syntax error.

#!/bin/bash

a=10

b=10

if [ $a == $b ]

then

echo "a is equal to b

fi

69
The case esac statements

Shell supportcase...esacstatement which handles exactly this situation,


and it does so more efficiently than repeated if...elif statements.

Shell supportcase...esacstatement which handles exactly this situation,


and it does so more efficiently than repeated if...elif statements.

Syntax

case word in

pattern1)

70
Cont

Give you attention on the spaces between braces and expression. This space is
mandatory otherwise you would get syntax error.

#!/bin/bash

a=10

b=10

if [ $a == $b ]

then

echo "a is equal to b

fi

71
Example

#!/bin/bash
language=python
Case $language in
php) echo learn php at w3schools
;;
java) echo install jdk first.
;;
python) echo download from http://www.python.org/.
;;
esac
72
Shell Loop Types

Loops are a powerful programming tool that enable you


to execute a set of commands repeatedly.

The while Loop

The while loop enables you to execute a set of commands


repeatedly until some condition occurs.

73
Syntax

while command

do

Statement(s) to be executed if command is true

done

74
Example
#!/bin/bash

a=0 Shellcommandis

while [ $a lt 10 ] evaluated. If the resulting


value istrue, given
do
statement(s)are executed.
echo $a Ifcommandisfalsethen no
statement would be
a=`expr $a + 1`
executed
done
75
The for Loop

The for loop operate on lists of items. It repeats a set of


commands for every item in a list.

Syntax

for var in word1 word2 ... wordN

do

Statement(s) to be executed for every word.

done
76
Example 1
#!/bin/bash
for var in 0 1 2 3 4 5 6 7 8
do
echo $var
done

Prints values from 0 to 8

77
Example 2
#!/bin/bash
for item in *
do
if [ -d $item ]
then
echo $item
fi
done

78
Cont

Note: if we want to display all files in the working


directory it is simply change d with f (since we are
working for files)
Until loop
To execute a set of commands while some condition is
true. Sometimes you need to execute a set of commands
until a condition is true.

79
Syntax

until command
do
Statement(s) to be executed until command is true.
done

80
Example
#!/bin/bash

a=0 Shellcommandis

while [ $a lt 10 ] evaluated. If the resulting


value istrue, given
do
statement(s)are executed.
echo $a Ifcommandisfalsethen no
statement would be
a=`expr $a + 1`
executed
done
81
Shell Functions

82
What are functions?

Shell functions are a way to group commands for later


execution, using a single name for those group. The name of
the group must be unique within the shell or script.
All the commands that make up a function are executed like
regular commands. When calling on a function as a simple
command name, the list of commands associated with that
function name is executed. A function is executed within the
shell in which it has been declared: no new process is
created to interpret the commands.

83
Function shell scripting

Does shell function is procedures or functions?

The definition of a function is traditionally that is returns a


single value, and does not output anything.
A procedure does not return a value, but may produce an
output.
A shell function may do neither, either or both
It is generally accepted that in shell scripted they are called
functions.

84
Function shell

A function may return a value in one of those ways:

A. Change the state of a variable(s).


B. Use the exit command to end the shell script.
C. Use the return command to end the function and return the
supplied value to the calling section of the shell script.
D. Echo output, which will be caught by the caller just as
c=expr $a + $b is caught.

85
Cont

Function enable us to break down the overall functionality


of a script into smaller, logical subsections, which can then
be called upon to perform their individual task when it is
needed.
For the purpose of performing repetitive tasks better to
create code reuse. Is an important part of modern
programing principles.
So that, shell functions are similar to subroutines,
procedures and functions in other programing languages.

86
Cont

Function enable us to break down the overall functionality


of a script into smaller, logical subsections, which can then
be called upon to perform their individual task when it is
needed.
For the purpose of performing repetitive tasks better to
create code reuse. Is an important part of modern
programing principles.
So that, shell functions are similar to subroutines,
procedures and functions in other programing languages.

87
Example

#!/bin/bash
#define our function here
Hello () {
echo hello world
}
#invoke our function here
Hello

88
Pass parameters to a functions

You can define a function which would accept parameters


while calling those function. These parameters would be
represented by $1, $2,
Like #definition
hello () {
echo hello world $1 $2
}
#invoke
hello Gentle man

89
Returning values from functions
If we want to terminate execution of the function, then there
is a way to come out of a defined function
Based on this we can return any value from our function
using the return command.
Like return code
code can be anything you choose

90
Example

#!/bin/bash

#define our function here


hello () {
echo hello world $1 $2
return 10
}

#invoke function here


hello gentle man

#capture value returned


ret=$?
echo returned value is $ret
91
Nested functions

One of the more interesting features of functions is that they


can call themselves as well as call other functions. A function
that calls itself is known as a recursive function.

92
Example

#!/bin/bash

#define our function here


hello () {
echo hello world $1 $2
return 10
}

#invoke function here


hello gentle man

#capture value returned


ret=$?
echo returned value is $ret
93
Different versions of the same function appear in a script?

When a function is defined multiple times, the final version is


displayed what is invoked.
Example
#!/bin/bash
func () {
echo this is the first version of func ().
}
func () {
echo this is the second version of func ().
}
func
exit $?

The output is this is the second version of func ().


94
Examples that require users to input value

#!/bin/bash

function () {
echo Dear customer please choose three /3/ models of car that you
want to buy.
read car1
read car2
read car3
}
function ()
echo dear customer, you have choose first model : $car1
echo dear customer, you have choose second model : $car2
echo dear customer, you have choose third model : $car3

95
Examples that require users to input value

#!/bin/bash

function () {
echo Dear customer please choose three /3/ models of car that you
want to buy.
read car1
read car2
read car3
}
function ()
echo dear customer, you have choose first model : $car1
echo dear customer, you have choose second model : $car2
echo dear customer, you have choose third model : $car3

96
Examples that require users to input value

#!/bin/bash

function () {
echo Dear customer please choose three /3/ models of car that you
want to buy.
read car1
read car2
read car3
}
function ()
echo dear customer, you have choose first model : $car1
echo dear customer, you have choose second model : $car2
echo dear customer, you have choose third model : $car3

97
User Management and File permission

98
User management is a critical part of maintaining a
secure system. Ineffective user and privilege
management often lead many systems into being
compromised. Therefore, it is important that you
understand how you can protect your server/DB
through simple and effective user account
management techniques.

99
Enable the root account

sudo passwd
To disable the root account password, use the
following passwd syntax:

sudo passwd -1 root


usermod --expiredate 1
100
Adding and Deleting Users

The process for managing local users and groups is straightforward and
differs very little from most other GNU/Linux operating systems. Ubuntu
and other Debian based distributions encourage the use of the "adduser"
package for account management.
To add a user account, use the following syntax, and follow the prompts to
give the account a password and identifiable characteristics, such as a full
name, phone number, etc.

sudo adduser username


To delete a user account and its primary group, use the following
syntax:

sudo deluser username


101
To temporarily lock or unlock a user account:

sudo passwd -l username


sudo passwd -u username
To add or delete a personalized group, use the following
syntax, respectively:

sudo addgroup groupname


sudo delgroup groupname
102
To add a user to a group, use the following syntax:

sudo adduser username groupname

sudo usermod -c "GuestUser" nixUser

cat /etc/passwd | grep nixUser

103
User Profile Security

When a new user is created, the adduser utility creates a brand new home
directory named /home/username. The default profile is modeled after the
contents found in the directory of /etc/skel, which includes all profile basics.
By default, user home directories in Ubuntu are created with world
read/execute permissions. This means that all users can browse and access
the contents of other users home directories. This may not be suitable for
your environment.

To verify your current user home directory permissions

ls -ld /home/username
104
Password Expiration

To easily view the current status of a user account, use the following syntax:

sudo chage -l username


To set any of these values, simply use the following syntax, and follow
the interactive prompts:

sudo chage username


sudo chage -E 01/31/2016
-m 5 -M 90 -I 30 -W 14
username 105
Viewing File Permissions

To view the permissions on a file or directory, issue the command ls -l


<directory/file>. Remember to replace the information in the < > with the
actual file or directory name. Below is sample output for the ls command:
The permission in the command line is displayed as: _rwxrwxrwx 1
owner:group
User rights/Permissions
1. The first character that I marked with an underscore is the special
permission flag that can vary.
2. The following set of three characters (rwx) is for the owner permissions.
3. The second set of three characters (rwx) is for the Group permissions.
4. The third set of three characters (rwx) is for the All Users permissions.
Following that grouping since the integer/number displays the number of
hardlinks to the file.

106
Read, Write & Execute Permissions

Permissions are the rights to act on a file or directory. The basic


rights are read, write, and execute.
Read - a readable permission allows the contents of the file to be
viewed. A read permission on a directory allows you to list the
contents of a directory.
Write - a write permission on a file allows you to modify the
contents of that file. For a directory, the write permission allows
you to edit the contents of a directory (e.g. add/delete files).
Execute - for a file, the executable permission allows you to run
the file and execute a program or script. For a directory, the
execute permission allows you to change to a different directory
and make it your current working directory. Users usually have a
default group, but they may belong to several additional groups.

107
Changing Directory and File Permissions

To view file permissions and ownership on files and directories, use the ls
-al command. The adoption is to show hidden files or all files, and
the l option is for the long listing. The output will be similar to the
following:

drwxr-xr-x 2 user user 4096 Jan 9 10:11 documents

``drwxr-xr-x`` are the permissions


``2`` is the number of files or directories
``user`` is the owner
``user`` is the group
``4096`` is the size
``Jan 9 10:11`` is the date/time of last access
``documents`` is the directory
108
Chmod Command
The command chmod is short for change mode. Chmod is used to change
permissions on files and directories. The command chmod may be used
with either letters or numbers (also known as octal) to set the permissions.
The letters used with chmod are in the table below:
It is important to remember that the first character of the first column of a file
listing denotes whether it is a directory or a file. The other nine characters are
the permissions for the file/directory. The first three characters are for the
user, the next three are for the group, and the last three are for others. The
example drwxrw-r is broken down as follows:

d is a directory
rwx the user has read, write, and execute permissions
rw- the group has read and write permissions
r all others have read only permissions
109
Chmod Octal Format
The execute permission is equal to the number one (1), the write
permission is equal to the number two (2), and the read permission is
equal to the number four (4). Therefore, when you use the octal format,
you will need to calculate a number between 0 and 7 for each portion of
the permission. A table has been provided below for clarification.

110
Changing File Ownership and group

By default, all files are owned by the user who creates them and by that
users default group. To change the ownership of a file, use
the chown command in the chown user:group /path/to/file format. In the
following example, the ownership of the list.html file will be changed to
the cjones user in the marketing group:

chown -R user list.html

Chgrp R group1 list.html

111

Das könnte Ihnen auch gefallen