Upload
reece
View
26
Download
0
Embed Size (px)
DESCRIPTION
Linux Command – part2. Changing to a different directory. % cd Will take you to the parent directory % cd / This command will take you to the root directory. Environment variables :. where the shell stores information that may be useful to the user’s shell session. - PowerPoint PPT Presentation
Citation preview
Linux Command – part2
Changing to a different directory
% cdWill take you to the parent directory
% cd /This command will take you to the root
directory
Environment variables :
where the shell stores information that may be useful to the user’s shell session.
Examples of environment variables include:
HOSTNAME=localhost SHELL=/bin/bash HOME = your homeTo print the variable value, Type:echo $SHELL
Reading manual man = manual$man
With the man command, you can retrieve the information in the manual and display it as text output on your screen. To use the man command.
IF you want to read a manual for ls command, type:
$ man lsTo exit from the manual page, simply press Q
File permission Keep users from accessing other users’
private files To protect important system files
permissions bitsrwx rwx rwxOwner’s| Group | Others
r = read w = write x = execute
File permission (cont.)For Files:
"Read" means to be able to open and view the file "Write" means to overwrite or modify the file "eXecute" means to run the file as a binary
files are executable only if they are programs and shell scripts, not useful for data files.
For Directories: "Read" means to be able to view the contents of the directory "Write" means to be able to create new files/directories or delete
files/directories within the directory "eXecute" means to be able to "Change Directory" (cd) into the directory
= permission to access the directory.
How to view the permission for a file or directory? $ ls -al
File permission (cont.)For Files:
"Read" means to be able to open and view the file "Write" means to overwrite or modify the file "eXecute" means to run the file as a binary
files are executable only if they are programs and shell scripts, not useful for data files.
For Directories: "Read" means to be able to view the contents of the directory "Write" means to be able to create new files/directories or delete
files/directories within the directory "eXecute" means to be able to "Change Directory" (cd) into the directory
= permission to access the directory.
How to view the permission for a file or directory? $ ls -al
File permission (cont.) Only the owner of a file can change its
permission. How to set file permission?
Use the command chmod(change file mode bits).
chmod has two notations: Numeric(octal) notation. Symbolic notation.
Change permission on a file - numeric
The file permissions aren't represented by characters. Instead, they are represented by a three-digit octal number.
The first digit specifies the permission of the Owner
The second digit specifies the permission of the Groups
The third digit specifies the permission of the Others
Change permission on a file - numeric
4 = read (r)2 = write (w)1 = execute (x)0 = no permission (-) Octal
#(421) Binary permissio
n
0 0+0+0 000 ---
1 0+0+1 001 --x
2 0+2+0 010 -w-
3 0+2+1 011 -wx
4 4+0+0 100 r--
5 4+0+1 101 r-x
6 4+2+0 110 rw-
7 4+2+1 111 rwx
725
4+2+1 0+2+0
rwx -w- r-x
If the permission is
4+0+1
Change permission on a file – symbolic Permissions are represented by characters rwx
This gives “who” the specified permissions for a given filename.
The “who” is a list of letters re going to be giving permissions to. These may be specified in any order.
+ add the selected permission. - remove the selected permission.
chmod who+
permission filename-
u The user who owns the file (this means “you.”)
g The group the file belongs to.
o The other users not in the file’s group.
a all of the above (an abbreviation for ugo)
Change permission on a fileFor r, w, x octal value is 4,2,1 respectively
$ chmod 777 file-name rwxrwxrwx
$ chmod 755 file-name rwxr-xr-x
owner(u) group(g) other(o) all(a) rwxrwxrwx
$ chmod a-w file-name r-xr-xr-x
$ chmod go-rwx file-name rwx------
owner(u) group(g) other(o) all(a) ---------
$ chmod u+rw file-name rw-------
Change permission on a file - Examples Using numeric notation, change the permission
of a file called S.txt so that the owner can read, write and execute it where the group can write and execute and others can only read.
The first digit will specifies the owner’s permission : 4 ( read ) + 2 (write ) + 1 ( execute ) = 7.
The second digit will specifies the group’s permission : 0 (no read ) + 2 (write ) + 1 ( execute ) = 3.
The third digit will specifies the others’ permission : 4 (read ) + 0 (no write ) + 0 (no execute ) = 4
So the command will be :chomd 734 S.txt
Change permission on a file - Examples Using symbolic notation, remove write
permission from the owner and groups.
chmod gu-w
Using file-matching metacharacters
$ ls a* The first example matches any file that begins with a
apple
$ ls g* The second example matches any file that begins with g
grape grapefruit
$ ls g*t This example matches any file beginning with g and ending in t
grapefruit
$ls *e* matches any file that contains e in the name
apple grape grapefruit watermelon
$ ls *n* matches any file that contains n in the name
banana watermelon
16
Using file-matching metacharacters
This matches any one of the characters between the brackets […]
$ls [abw]* any file beginning with a,b or w is matched
apple banana watermelon
$ls [agw] * [ne] any file that begins with a ,g or w and also ends with either n or e is matched
apple grape watermelon
$ls [a-g] * any filenames beginning with letter from a through g are matched
apple banana grape grapefruit
Using file-matching metacharacters
$ls ????e The first example matches any five-character file that ends in e
Apple grape
$ls g???e* The second matches any file that begins with g and has e as its fifth character
grape grapefruit
Using file-matching metacharacters – Examples
Write a command to list any file that begins with B.
ls B*
* means : any number of characters.
Write a command to list any file begins with d and ends with f
ls d*f
Write a command to list any file begins with a or b , followed by 2 characters.
ls [ab]??
Echo command
Use echo command to display text or value of variable.
"Double Quotes“literally print everything inside the single quote. Even the special
variables such as $HOSTNAME will be print as $HOSTNAME
'Single quotes‘ display the real meaning of special variables
`Back quote`Used with commands only.To execute command