working with linux lab 1 1. login and logout account – username & password – note: linux is...

22
Working with Linux Lab 1 1

Upload: abel-townsend

Post on 12-Jan-2016

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Working with Linux

Lab 1

1

Page 2: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Login and logout

• Account

– username & password

– Note:

• Linux is case-sensitive

• Administrator: username = root

• Logout: exit, Ctrl+D

2

Page 3: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Linux File System

3

(C)

WINDOWS Program Files

Fonts System32

….

….

(D)

Data Music

OS ….

(/)

boot home

….

….

etc

khoa student1

root

Windows File SystemLinux File System

Page 4: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Directory/file commands

• List contents of directory : ls [-a] [-l] [directory_name]

• Print working directory: pwd• Change working directory :

cd directory_nameE.g. cd /home

• Create new directory : mkdir directory_name

• Remove a directory:rm -r directory_name

• Some special symbols : ~ : home directory.. : parent directory

4

Page 5: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Directory/file commands

• Display file content :

cat filename or more filename

head filename or tail filename

• Copy file(s) or directory:

cp [-r] source_file destination_file

• Remove file or directory

rm –r file_name

• Move (rename) file(s)/directory

mv old_path new_path5

Page 6: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

File system and permissions

• Each user may owns one or more directories/files

• Each user has different access rights in different

directories/filesusers can share their data together

users also can protect their private data

6

Page 7: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

File system and permissions

• Access right on directory/file– read (r)

– write (w)

– execute (x)

• Each directory/file has 9 access-right bits, divide into 3 groups

as follow :

– owner

– group (e.g. people the same project team)

– others (people in public domain)

7

Page 8: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

File system and permissions

8

Page 9: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Changing access rights (1)

• Symbolic chmod who op mode [-R] file(s)

• Who: u : owner

g : group

o : others

a : all

• Mode: r : read

w : write

x : execute

• Op + : grant more rights

- : revoke rights

= : reset rights

9

Page 10: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Changing access rights (2)

• Example$ touch temp

$ ls –l temp-rw-r--r-- 1 user1 staff 0 Jun 11 11:44 temp

$ chmod o-r temp

$ ls -l temp-rw-r----- 1 user1 staff 0 Jun 11 11:44 temp

$ chmod u+x, o+r temp

$ ls -l temp

-rwxr--r-- 1 user1 staff 0 Jun 11 11:44 temp

10

Page 11: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Changing access rights (3)

• Numeric: chmod xyz [-R] file(s)

read = 4 write = 2 execute = 1

11

Octal value Access right

7 rwx

6 rw-

5 r-x

4 r--

3 -wx

2 -w-

1 --x

0 ---

Page 12: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Changing access rights (4)

• Example: some common access rights of

directory/file(s)

12

Octal value Access right

600 rw-------

644 rw-r--r--

700 rwx------

751 rwxr-x--x

775 rwxrwxr-x

777 rwxrwxrwx

Page 13: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Changing access rights (5)

• Example$ touch abc

$ ls –l abc-rw-r--r-- 1 user1 staff 0 Jun 11 11:44 abc

$ chmod 555 abc

$ ls -l abc-r-xr-xr-x 1 user1 staff 0 Jun 11 11:44 abc

$ chmod 775 abc

$ ls -l abc

-rwxrwxr-x 1 user1 staff 0 Jun 11 11:44 abc

13

Page 14: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Advanced utilities (1)

• Who is who?who [option]

• Print current host namehostname

• Where do they come from?which [filename]

• How much disk usage?df [option]

• Clear screenclear OR Ctrl + L

14

Page 15: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Advanced utilities (2)

• Find a specified file :

find path –name filename

• Find lines in file matching a pattern

grep pattern file_name

• Mount and unmount file system

mount -t filesystem device_file mount_point

umount mount_point

15

Page 16: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

vi editor

• Interactive simple editor

• Can not use mouse

• Text editing on a buffer

• Appears on most Unix or Unix-like system

16

Page 17: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

vi usage

17

syntax meaning

vi filename open/create file

a or i change to edit mode

ESC → wq! save and quit

ESC → q! not save and quit

Page 18: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Cursor movement in vi

18

Cmd Meaning

n move cursor left n character(s)

n move cursor down n character(s)

n move cursor up n character(s)

n move cursor right n character(s)

Enter move cursor to beginning of next line

G move cursor to the last line

nw move cursor left n word(s)

nW move cursor right n word(s)

Page 19: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Text manipulation commands

19

Cmd Meaning

nx delete n character(s) from current cursor position

nX delete n character(s) immediately preceding current cursor position

D, d$ delete all characters from current cursor position to end of line

d0, d| delete all characters from left column of screen to character preceding current cursor position on current line

Page 20: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Text manipulation commands

20

Cmd Meaning

ndd delete n line(s) beginning at current line

dG delete all lines, starting with current line, through end of file

d1G delete all lines, starting with current line, through beginning of file

ndw delete from cursor position through end of n following word

ndb delete from nearest preceding word through character before current cursor position

J join the next line at the end of current line

Page 21: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Text manipulation commands

21

Cmd Meaning

~ change case of current character

r replace single character at cursor position

ncc change n line(s) beginning at current line

cG change all lines from current line through end of file

ncw change n word(s) on the left of cursor

ncb change n word(s) on the right of cursor

Page 22: Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,

Text manipulation commands

22

Cmd Meaning

nY, nyy copy (yank) n line(s) into buffer

nyw copy (yank) n word(s) into buffer

y$ copy (yank) from current cursor position through end of line into buffer

yG copy (yank) from current line through end of file into buffer

p Insert buffer content at the line after current line

P Insert buffer content at the line above current line