introduction to freebsd commands
TRANSCRIPT
Intro. to
FreeBSD commands
2013 NCU CSIE INFO CLUB & SNMG ©
Author : Egg
About .
Egg
資工 3A
跑步、排球、玩Game
Outline
1.Unix (-Like), Linux ?
- FreeBSD
2.Commands
- Network
- File access
- Owner & Group
- User
Unix (-Like), Linux ?
Unix (-Like), Linux ?
Unix
Unix-Like
Linux
總之
Unix --> BSD --> FreeBSD
--> Linux ( Unix-Like )
FreeBSD
Pros & Cons
Image from : http://blog.secaserver.com
Feature
1. Free
2. Stable
4. No desktop (default)
3. Multi-User
- Open Source
- Ports
- Terminal
- Permission
Start your FreeBSD
VirtualBox
Terminal
Commands
User
User
(default: root) name
password
Login
Exit Add user
Change password
Relate .
Login login: root Password:
root@:~ #
Exit root@:~ # exit
login:
指令: passwd
Change password
用法: passwd [user]
root@:~ # passwd root
Changing local password for root New Password: Retype New Password: root@:~ #
User root ?
root
系統管理員
擁有最高權限
(administrator)
執行所有的指令
處理所有的檔案
能夠
指令: adduser
Add new user
用法: 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 : ***** ..
Group
Home
/
Task 1
更新 root 的密碼
passwd
創立一個新的使用者並登入
useradd, exit
root@ : ~ #
使用者名稱 當前目錄位置
: root : ~
~ 使用者家目錄
/home/(user)
/root root 家目錄
其他使用者家目錄
/root , /home ?
一切都從 / 開始
目錄結構
/
/root
/home
/var
/usr
/bin
/sbin
/boot
.
.
/home/egg
/home/inin
/var/log
.
.
.
.
/var/mail
(根目錄)
指令: cd
Change Directory
用法: cd 目錄路徑
目錄路徑 . ..
/var
當前目錄
上層目錄
var 目錄的絕對路徑
egg@:~ % cd .
egg@:~ %
egg@:~ % cd ..
egg@:/home %
egg@:/home % cd /var
egg@:/var %
指令: ls
List
用法: ls
(directory contents)
-a
-l
[ -al ]
全部的檔案,連同隱藏檔 ( 開頭為 . 的檔案 )
列出長資料串,包含檔案屬性與權限等
選項與參數
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
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 ...
Owner & Group
-r--r--r-- root wheel COPYRIGHT drwxr-xr-x root wheel bin lrwxr-xr-x root wheel home->usr/home
檔案擁有者 檔案所屬群組 檔案類型權限 檔名
Owner Group
- 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 連結檔
目錄
檔案
- 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 可執行
可寫
可讀
擁有者權限 群組權限 其他人權限
File access
File
Read
Write
Read Edit(New) Move
Relate .
Execute
Remove Copy
指令: cat, more
Read (Print) file
用法: 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 離開
指令: vi
Edit (New) file
用法: 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 的檔案,寫入你的 學號 和 生日 。
再切換 User 為 一般使用者 ,進入 /tmp 觀看並修改 about 檔案,將內容加上 日期。
ex. 1005020xx 1993/xx/xx vi cd :wq
cat | more ex. 1005020xx 1993/xx/xx , today : 2013/10/21
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 9 Oct 21 13:55 about
Owner : root
Group : wheel
Other : egg
r, w, x
r
r
Change file owner/mode
指令: 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
指令: chmod
Change file mode
用法: chmod _ _ _ (filename)
Owner group other
_ _ _ r
w
x
rwx: 4+2+1 =7 rw : =6
r : =4
→ 4
→ 2
→ 1
指令: 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
Network
root@:/tmp # sysinstall
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 ...
Need some help ?
指令: man
Display manual pages
用法: man (command)
root@:/ # man ls
Name ls -- list directory contents SYNOPSIS ls [-A...] ...
Final.
指令: shutdown
Close down the system
用法: shutdown [-p] time
root@:/ # shutdown –p now
-p 選項與參數
halt, power off
End
SNMG System and Network Management Group
We are
Thanks for
中央資工系學會 資訊部
NCU CSIE INFO CLUB