62
Intro. to FreeBSD commands 2013 NCU CSIE INFO CLUB & SNMG © Author : Egg

Introduction to FreeBSD commands

  • Upload
    -

  • View
    420

  • Download
    8

Embed Size (px)

Citation preview

Page 1: Introduction to FreeBSD commands

Intro. to

FreeBSD commands

2013 NCU CSIE INFO CLUB & SNMG ©

Author : Egg

Page 2: Introduction to FreeBSD commands

About .

Egg

資工 3A

跑步、排球、玩Game

Page 3: Introduction to FreeBSD commands

Outline

1.Unix (-Like), Linux ?

- FreeBSD

2.Commands

- Network

- File access

- Owner & Group

- User

Page 4: Introduction to FreeBSD commands

Unix (-Like), Linux ?

Page 5: Introduction to FreeBSD commands

Unix (-Like), Linux ?

Unix

Unix-Like

Linux

Page 6: Introduction to FreeBSD commands

總之

Unix --> BSD --> FreeBSD

--> Linux ( Unix-Like )

Page 7: Introduction to FreeBSD commands

FreeBSD

Page 8: Introduction to FreeBSD commands

Pros & Cons

Page 9: Introduction to FreeBSD commands

Image from : http://blog.secaserver.com

Feature

1. Free

2. Stable

4. No desktop (default)

3. Multi-User

- Open Source

- Ports

- Terminal

- Permission

Page 10: Introduction to FreeBSD commands

Start your FreeBSD

Page 11: Introduction to FreeBSD commands

VirtualBox

Page 12: Introduction to FreeBSD commands

Terminal

Page 13: Introduction to FreeBSD commands

Commands

Page 14: Introduction to FreeBSD commands

User

Page 15: Introduction to FreeBSD commands

User

(default: root) name

password

Login

Exit Add user

Change password

Relate .

Page 16: Introduction to FreeBSD commands

Login login: root Password:

root@:~ #

Exit root@:~ # exit

login:

Page 17: Introduction to FreeBSD commands

指令: passwd

Change password

用法: passwd [user]

root@:~ # passwd root

Changing local password for root New Password: Retype New Password: root@:~ #

Page 18: Introduction to FreeBSD commands

User root ?

Page 19: Introduction to FreeBSD commands

root

系統管理員

擁有最高權限

(administrator)

執行所有的指令

處理所有的檔案

能夠

Page 20: Introduction to FreeBSD commands

指令: adduser

Add new user

用法: adduser

root@:~ # adduser

Page 21: Introduction to FreeBSD commands

Username: egg Full name: egg Uid (Leave empty for default ): Login group [egg]: Login group is egg. Invite egg into other groups? [ ]: Login class [default]: Shell (sh csh tcsh nologin) [sh]: csh Home directory [/home/egg]: Home directory permissions (Leave empty for default): Use password-based authentication? [yes]: Use an empty password? (yes/no) [no]: Use a random password? (yes/no) [no]: Enter password: Enter password again: Lock out the accout after creation? [no]: Username : egg Password : ***** ..

Group

Home

/

Page 22: Introduction to FreeBSD commands

Task 1

更新 root 的密碼

passwd

創立一個新的使用者並登入

useradd, exit

Page 23: Introduction to FreeBSD commands

root@ : ~ #

使用者名稱 當前目錄位置

: root : ~

Page 24: Introduction to FreeBSD commands

~ 使用者家目錄

/home/(user)

/root root 家目錄

其他使用者家目錄

Page 25: Introduction to FreeBSD commands

/root , /home ?

Page 26: Introduction to FreeBSD commands

一切都從 / 開始

目錄結構

Page 27: Introduction to FreeBSD commands

/

/root

/home

/var

/usr

/bin

/sbin

/boot

.

.

/home/egg

/home/inin

/var/log

.

.

.

.

/var/mail

(根目錄)

Page 28: Introduction to FreeBSD commands

指令: cd

Change Directory

用法: cd 目錄路徑

目錄路徑 . ..

/var

當前目錄

上層目錄

var 目錄的絕對路徑

egg@:~ % cd .

egg@:~ %

egg@:~ % cd ..

egg@:/home %

egg@:/home % cd /var

egg@:/var %

Page 29: Introduction to FreeBSD commands

指令: ls

List

用法: ls

(directory contents)

-a

-l

[ -al ]

全部的檔案,連同隱藏檔 ( 開頭為 . 的檔案 )

列出長資料串,包含檔案屬性與權限等

選項與參數

Page 30: Introduction to FreeBSD commands

egg@:/var % cd / egg@:/ % ls

COPYRIGHT entropy libexec rescue tmp bin etc media root usr boot home mnt sbin var dev lib proc sys

egg@:/ % ls -a

. .sujournal entropy media sbin

.. COPYRIGHT etc mnt sys

.cshrc bin home proc tmp

.profile boot lib rescue usr

.snap dev libexec root var

Page 31: Introduction to FreeBSD commands

egg@:/ % ls -l

Total 69 -r--r--r-- 1 root wheel 61099 Sep 27 12:04 COPYRIGHT drwxr-xr-x 2 root wheel 1024 Sep 27 12:00 bin drwxr-xr-x 7 root wheel 1024 Sep 27 12:00 boot ...

egg@:/ % ls -al

Total 32889 drwxr-xr-x 18 root wheel 1024 Sep 27 12:04 . drwxr-xr-x 18 root wheel 1024 Sep 27 12:00 .. -rw-r--r-- 2 root wheel 968 Sep 27 12:00 .cshrc ...

Page 32: Introduction to FreeBSD commands

Owner & Group

Page 33: Introduction to FreeBSD commands

-r--r--r-- root wheel COPYRIGHT drwxr-xr-x root wheel bin lrwxr-xr-x root wheel home->usr/home

檔案擁有者 檔案所屬群組 檔案類型權限 檔名

Owner Group

Page 34: Introduction to FreeBSD commands

- r-- r-- r-- d rwx r-x r-x l rwx r-x r-x

-r--r--r-- 1 root wheel 61099 Sep 27 12:04 COPYRIGHT drwxr-xr-x 2 root wheel 1024 Sep 27 12:00 bin lrwxr-xr-x 1 root wheel 8 Sep 27 12:00 home->usr/home

檔案類型權限

檔案類型

-

d

l 連結檔

目錄

檔案

Page 35: Introduction to FreeBSD commands

- r-- r-- r-- d rwx r-x r-x l rwx r-x r-x

-r--r--r-- 1 root wheel 61099 Sep 27 12:04 COPYRIGHT drwxr-xr-x 2 root wheel 1024 Sep 27 12:00 bin lrwxr-xr-x 1 root wheel 8 Sep 27 12:00 home->usr/home

檔案類型權限

r

w

x 可執行

可寫

可讀

擁有者權限 群組權限 其他人權限

Page 36: Introduction to FreeBSD commands

File access

Page 37: Introduction to FreeBSD commands

File

Read

Write

Read Edit(New) Move

Relate .

Execute

Remove Copy

Page 38: Introduction to FreeBSD commands

指令: cat, more

Read (Print) file

用法: cat (filename)

more (filename) egg@:/ % cat /etc/group

bin:*:7: news:*:8: man:*:9: games:*:13: ftp:*:14: ...

Page 39: Introduction to FreeBSD commands

Read (Print) file

more 可翻頁檢視

egg@:/ % more /etc/group

# $FreeBSD: (...) # wheel:*:0:root daemon:*:1: kmem:*:2: sys:*:3: tty:*:4: ... --More--(74%)

[space] 向下翻一頁

/字串 向下搜尋 "字串" 這個關鍵字

q 離開

Page 40: Introduction to FreeBSD commands

指令: vi

Edit (New) file

用法: vi [filename]

egg@:/ % cd ~ egg@:~ % vi test

~ ~ ~ ~

Page 41: Introduction to FreeBSD commands

Edit (New) file

vi 文書處理軟體

一般模式

編輯模式

指令列模式

i

[Esc]

:

Page 42: Introduction to FreeBSD commands

Edit (New) file

vi 文書處理軟體

i 進入編輯模式

Hello! You can call me Egg. ~ ~ ~ ~

Page 43: Introduction to FreeBSD commands

Edit (New) file

vi 文書處理軟體

[Esc] 進入一般模式

h j k l

← ↑ ↓ →

d 刪除

d3l 向右刪除3個字元

dd 刪除一整列

yy 複製一列

p 貼上

Page 44: Introduction to FreeBSD commands

Edit (New) file

vi 文書處理軟體

: 進入指令列模式

:w 將資料寫入檔案

:q 離開 vi

:q! 已修改檔案,但不想儲存,強制離開

:w [filename] 將資料儲存成另一個檔案, 檔名為 "filename"

Page 45: Introduction to FreeBSD commands

Task 2

切換 User 為 root ,並在 /tmp 中建立一個檔名 about 的檔案,寫入你的 學號 和 生日 。

再切換 User 為 一般使用者 ,進入 /tmp 觀看並修改 about 檔案,將內容加上 日期。

ex. 1005020xx 1993/xx/xx vi cd :wq

cat | more ex. 1005020xx 1993/xx/xx , today : 2013/10/21

Page 46: Introduction to FreeBSD commands

Wrong ?

Page 47: Introduction to FreeBSD commands

1005020xx 1993/xx/xx, today:2013/10/21 ~ ~ :wq Read-only file, not written; use ! to override.

1005020xx 1993/xx/xx, today:2013/10/21 ~ ~ :wq! Error: about: Permission denied.

Page 48: Introduction to FreeBSD commands

:q! egg@:/tmp % ls -l

total 4 -rwxr--r-- 1 root wheel 9 Oct 21 13:55 about

Owner : root

Group : wheel

Other : egg

r, w, x

r

r

Page 49: Introduction to FreeBSD commands

Change file owner/mode

Page 50: Introduction to FreeBSD commands

指令: chown

Change file owner

用法: chown (O) [: G] (filename)

root@:/tmp # chown egg about root@:/tmp # ls -l

total 4 -rwxr--r-- 1 egg wheel 9 Oct 21 13:55 about

root@:/tmp # chown egg:egg about root@:/tmp # ls -l

total 4 -rwxr--r-- 1 egg egg 9 Oct 21 13:55 about

Page 51: Introduction to FreeBSD commands

指令: chmod

Change file mode

用法: chmod _ _ _ (filename)

Owner group other

_ _ _ r

w

x

rwx: 4+2+1 =7 rw : =6

r : =4

→ 4

→ 2

→ 1

Page 52: Introduction to FreeBSD commands

指令: chmod

Change file mode

用法: chmod _ _ _ (filename)

root@:/tmp # chmod 747 about root@:/tmp # ls -l

total 4 -rwxr--rwx 1 root wheel 9 Oct 21 13:55 about

Page 53: Introduction to FreeBSD commands

Network

Page 54: Introduction to FreeBSD commands

root@:/tmp # sysinstall

Page 55: Introduction to FreeBSD commands

Ping

root@:/tmp # ping 8.8.8.8

Send the packets to network hosts

PING 8.8.8.8 (8.8.8.8): 56 data bytes 64 bytes from 168.95.1.1: icmp_seq=0 ttl=50 time=10.0 ms 64 bytes from 168.95.1.1: icmp_seq=1 ttl=50 time=10.2 ms ...

root@:/tmp # ping www.google.com

PING www.foofle.com (202.169.173.216): 56 data bytes 64 bytes from 202.169.173.216 : icmp_seq=0 ttl=58 time=10.0 ms 64 bytes from 202.169.173.216 : icmp_seq=1 ttl=58 time=10.2 ms ...

Page 56: Introduction to FreeBSD commands

Need some help ?

Page 57: Introduction to FreeBSD commands

指令: man

Display manual pages

用法: man (command)

root@:/ # man ls

Name ls -- list directory contents SYNOPSIS ls [-A...] ...

Page 58: Introduction to FreeBSD commands

Final.

Page 59: Introduction to FreeBSD commands

指令: shutdown

Close down the system

用法: shutdown [-p] time

root@:/ # shutdown –p now

-p 選項與參數

halt, power off

Page 60: Introduction to FreeBSD commands

End

Page 61: Introduction to FreeBSD commands

SNMG System and Network Management Group

We are

Page 62: Introduction to FreeBSD commands

Thanks for

中央資工系學會 資訊部

NCU CSIE INFO CLUB