Intro. to

FreeBSD commands

2013 NCU CSIE INFO CLUB & SNMG ©

Author : Egg
About .
Egg
資工 3A
跑步、排球、玩Game
Outline
1.Unix (-Like), Linux ?
- FreeBSD

2.Commands
- User
- Owner & Group
- File access
- Network
Unix (-Like), Linux ?
Unix (-Like), Linux ?
Unix
Unix-Like

Linux
總之
Unix --> BSD --> FreeBSD
--> Linux

( Unix-Like )
FreeBSD
Pros & Cons
Feature
1. Free

- Open Source

2. Stable - Ports

3. Multi-User
- Permission

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

4. No desktop
(default) - Terminal
Start your FreeBSD
VirtualBox
Terminal
Commands
User
User
name

(default: root)

password
Relate .

Login
Exit

Add user
Change password
Login
login: root
Password:
root@:~ #

Exit
root@:~ # exit

login:
Change password
指令: passwd
用法: passwd [user]
root@:~ # passwd root
Changing local password for root
New Password:
Retype New Password:
root@:~ #
User root ?
root
系統管理員 (administrator)
擁有最高權限
能夠

執行所有的指令

處理所有的檔案
Add new user
指令: adduser
用法: adduser
root@:~ # adduser
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
: *****
..

/

Home
Group
Task 1
更新 root 的密碼

passwd
創立一個新的使用者並登入
useradd, exit
root@ : ~ #
使用者名稱
: root

當前目錄位置
:~
~

使用者家目錄
/root

root 家目錄

/home/(user)

其他使用者家目錄
/root , /home ?
一切都從 / 開始
目錄結構
/boot
/root

/
(根目錄)

/home

/bin
/sbin

/var
/usr
.
.

/home/egg
/home/inin
.
.
/var/log
/var/mail
.
.
Change Directory
指令: cd
用法: cd 目錄路徑

egg@:~ % cd .
egg@:~ %
egg@:~ % cd ..

目錄路徑
. 當前目錄
.. 上層目錄
/var var 目錄的絕對路徑

egg@:/home %
egg@:/home % cd /var
egg@:/var %
List (directory contents)
指令: ls
用法: ls [ -al ]
選項與參數

-a

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

-l

列出長資料串,包含檔案屬性與權限等
egg@:/var % cd /
egg@:/ % ls
COPYRIGHT
bin
boot
dev

entropy
etc
home
lib

libexec
media
mnt
proc

rescue
root
sbin
sys

tmp
usr
var

entropy
etc
home
lib
libexec

media
mnt
proc
rescue
root

sbin
sys
tmp
usr
var

egg@:/ % ls -a
.
..
.cshrc
.profile
.snap

.sujournal
COPYRIGHT
bin
boot
dev
egg@:/ % ls -l
Total 69
-r--r--r-drwxr-xr-x
drwxr-xr-x
...

1
2
7

root
root
root

wheel
wheel
wheel

61099
1024
1024

Sep 27 12:04 COPYRIGHT
Sep 27 12:00 bin
Sep 27 12:00 boot

wheel
wheel
wheel

1024
1024
968

Sep 27 12:04 .
Sep 27 12:00 ..
Sep 27 12:00 .cshrc

egg@:/ % ls -al

Total 32889
drwxr-xr-x 18
drwxr-xr-x 18
-rw-r--r-- 2
...

root
root
root
Owner & Group
檔案類型權限

-r--r--r-drwxr-xr-x
lrwxr-xr-x

檔案擁有者 檔案所屬群組 檔名

root
root
root

wheel
wheel
wheel

Owner

Group

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

1
2
1

root
root
root

wheel 61099 Sep 27 12:04 COPYRIGHT
wheel 1024 Sep 27 12:00 bin
wheel
8 Sep 27 12:00 home->usr/home

檔案類型權限

檔案類型

r-rwx
rwx

r-r-x
r-x

r-r-x
r-x

-

檔案

d

目錄

l

d
l

連結檔
-r--r--r-drwxr-xr-x
lrwxr-xr-x

1
2
1

root
root
root

wheel 61099 Sep 27 12:04 COPYRIGHT
wheel 1024 Sep 27 12:00 bin
wheel
8 Sep 27 12:00 home->usr/home

檔案類型權限

d
l

r-rwx
rwx

r-r-x
r-x

r-r-x
r-x

r

w 可寫
x

擁有者權限

群組權限

其他人權限

可讀

可執行
File access
File
Read

Execute

Write
Relate .

Read Edit(New) Move
Remove
Copy
Read (Print) file
指令: cat, more
用法: cat (filename)
more (filename)
egg@:/ % cat /etc/group
bin:*:7:
news:*:8:
man:*:9:
games:*:13:
ftp:*:14:
...
Read (Print) file

more

可翻頁檢視

egg@:/ % more /etc/group
# $FreeBSD: (...)
#
wheel:*:0:root
daemon:*:1:
kmem:*:2:
sys:*:3:
tty:*:4:
...
--More--(74%)

[space] 向下翻一頁
/字串

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

q

離開
Edit (New) file
指令: vi
用法: vi [filename]
egg@:/ % cd ~
egg@:~ % vi test

~
~
~
~
Edit (New) file

vi

文書處理軟體
i

編輯模式
一般模式

[Esc]
:

指令列模式
Edit (New) file

vi
i

文書處理軟體

進入編輯模式

Hello! You can call me Egg.
~
~
~
~
Edit (New) file

vi

文書處理軟體

[Esc]

進入一般模式

← ↓ ↑ →
h

j

k

l

d 刪除
d3l 向右刪除3個字元
dd 刪除一整列
yy 複製一列
p 貼上
Edit (New) file

vi
:

文書處理軟體

進入指令列模式

:w 將資料寫入檔案
:q

離開 vi

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

將資料儲存成另一個檔案,
檔名為 "filename"
Task 2
切換 User 為 root ,並在 /tmp 中建立一
個檔名 about 的檔案,寫入你的 學號 和
生日 。
ex.

1005020xx 1993/xx/xx

cd vi :wq

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

1005020xx 1993/xx/xx , today : 2013/10/21

cat | more
Wrong ?
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.
:q!
egg@:/tmp % ls -l
total 4
-rwxr--r--

1 root

wheel

Owner : root
Group : wheel
Other : egg

9 Oct 21 13:55 about

r, w, x
r
r
Change file owner/mode
Change file owner
指令: chown
用法: 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
Change file mode
指令: chmod
用法: chmod _ _ _ (filename)
___

Owner group other

r → 4 rwx: 4+2+1
=7
w → 2 rw : =6
x → 1 r : =4
Change file mode
指令: chmod
用法: chmod _ _ _ (filename)
root@:/tmp # chmod 747 about
root@:/tmp # ls -l
total 4
-rwxr--rwx

1 root

wheel

9 Oct 21 13:55 about
Network
root@:/tmp # sysinstall
Ping
Send the packets to network hosts
root@:/tmp # ping 8.8.8.8
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
...
Need some help ?
Display manual pages
指令: man
用法: man (command)
root@:/ # man ls
Name
ls -- list directory contents
SYNOPSIS
ls [-A...]
...
Final.
Close down the system
指令: shutdown
用法: shutdown [-p] time
選項與參數

-p halt, power off
root@:/ # shutdown –p now
End
We are

SNMG
System and Network Management Group
Thanks for

中央資工系學會 資訊部
NCU CSIE INFO CLUB

Introduction to FreeBSD commands