1. 為 root 設(shè)置密碼
sudo passwd root
提示輸入密碼,第一次要輸入當前帳戶的密碼,之后輸入新密碼,再輸入新密碼的確認
密碼, root 的密碼就會設(shè)置成功。
2. 切換到 root 下進行作業(yè)
su root
3. 設(shè)置網(wǎng)絡(luò)代理,使 apt-get 能安裝軟件
(1)在/etc/apt目錄下新建文件 apt.conf
(2)編輯 apt.conf 內(nèi)容如下
Aquire::http::your_proxy:80;
(3)如果不想通過重啟來生效,可用如下命令:
export http_proxy=http://your_proxy:80
4. 只顯示當前路徑下的目錄
ls -l | grep ^d
5. 在 Ubuntu 里安裝 VMWare-tool
由于安裝VMware Tools需要針對新內(nèi)核重新編譯模塊,所以必須先安裝基本編譯系統(tǒng)和
內(nèi)核頭文件。
$ sudo apt-get install build-essential
$ sudo apt-get install linux-headers-`uname -r`
安裝VMware Tools。選擇VMware菜單VM|Install VMware Tools,系統(tǒng)會自動載入
CDROM,打開一個終端窗口執(zhí)行下列命令:
$ tar zxf /media/cdrom/VMwareTool-5.0.0-*.tar.gz
$ cd vmware-tools-distrib
$ sudo ./vmware-install.pl
安裝完畢后,在 /mnt 目錄下會有個 hgfs 目錄即安裝成功,通過 VMWare 的菜單 VM
-> Settings... -> Options -> Shared Folders 設(shè)置一文件夾,可實現(xiàn)Unbuntu
對此文件夾的共享訪問。
6. 使用 tar 對軟件打包解包
tar cjvf test.tar.bz2 test
tar zjvf test.tar.bz2
或者
tar czvf test.tar.gz test
tar xzvf test.tar.gz
7. 如何掛接/卸載 U 盤
mount -tvfat /dev/sdb1 /mnt/udisk
umount /mnt/udisk
8. 創(chuàng)建連接文件
ln -s /usr/local/emacs22/bin/emacs-22.1 emacs
9. 編譯 emacs22 源碼
(1)先安裝兩個必須的軟件包
sudo apt-get install libidl-dev
sudo apt-get install libgtk2.0-dev
(2)./configure --prefix=/usr/local/emacs22 \
--enable-font-backend --with-xft \
--with-freetype --with-gtk \
--with-x-toolkit=gtk
(3) make bootstrap
(4) make install
10 配置 IP 以訪問 Internet
(1) ifconfig eth0 ip netmask 255.255.255.0
(2) route add default gw gateway
(3) 編輯 /etc/resolv.conf 用以設(shè)置 DNS, 例如:
search domain.corp.company.com
nameserver 192.168.0.55
nameserver 192.168.0.88
11 使用 grep 匹配當前目錄下所有文件(包括子目錄)
grep -r 'your_contents' ./
12 殺掉進程
(1) 先通過 ps -aux 獲得進程的 PID
(2) kill -9 PID
13 boot ubuntu without starting X
(1) sudo gedit /etc/init.d/gdm
(2) add "exit 0" at the second line
14 修改 console 下的分辯率
(1) 編輯 /boot/grub/menu.lst
(2) 在 kernel 行尾添加 vga=value, 如:
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hda1 ro quiet splash vga=791
(3) vga 的值如何設(shè)置,可參考下表:
色深
|
640×480
|
800×600
|
1024×768
|
1280×1024
|
256
|
769
|
771
|
773
|
775
|
32000
|
784
|
787
|
790
|
793
|
65000
|
785
|
788
|
791
|
794
|
16.7 Mill.
|
786
|
789
|
792
|
795
|
15 遞歸顯示當前目錄下的內(nèi)容
ls -R $PWD
16 修改 /etc/profile 后無需重啟而使之立即生效
#. /etc/profile
注意 /etc/profile 前面的點 .
17 在 VMware Ubuntu 7.0.4 用 Ctrl+Alt+F1~F7 實現(xiàn)多用戶切換
在 VMware 里使用 Ubuntu 與真實機一樣,但卻無法用 Ctrl + Alt + F1~F7 實現(xiàn)多用戶切換。折騰了半天,原來是 VMware 將 Ctrl + Alt 用作了快捷鍵。可通過如下操作: VMware -> Edit -> Preference... -> Hot Keys,將里面默認的快捷鍵改成 Ctrl + Shift + Alt, 之后重啟 VMware ,就可在 Ubuntu 里通過 Ctrl + Alt + F1~F7 實現(xiàn)多用戶切換了。
18 獲知某一目錄的大小
du -sh /root
19 獲知用到了哪些共享庫文件
#readelf -a hello | grep -i 'share'
0x00000001 (NEEDED) Shared library: [libc.so.6]
20 以靜態(tài)方式指定 IP
(1) 編輯文件 /etc/network/interfaces, 添加內(nèi)容如下:
auto eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.0.0.0
gateway 10.0.0.1
(2) 重新啟動網(wǎng)絡(luò)服務(wù)
#/etc/init.d/networking restart
21 添加服務(wù)
(1)安裝網(wǎng)絡(luò)請求守護進程(如果需要)
sudo apt-get install openbsd-inetd
(2)配置端口并指定服務(wù)名
在 /etc/services 添加內(nèi)容如下:
hello 20001/tcp
其意義為 hello 這項服務(wù)的端口為 20001, 并且是一個 TCP 服務(wù)
(3)在 /etc/inetd.conf 中添加下面這一行
hello stream tcp nowait root /home/jbw/hello
各個參數(shù)意義如下:
<service_name> <sock_type> <proto> <flags> <user> <server_path> <args>
service_name: 服務(wù)名稱(這個服務(wù)名稱要和你在 /etc/services 中設(shè)置的服務(wù)名稱一致)
sock_type: stream 或 dgram
proto: 一般用 tcp/udp
flags: wait/nowait
user: 指定該程序要以哪一個用戶來啟動
server_path: 服務(wù)程序的全路徑
args: 服務(wù)程序的參數(shù)(可選)
(4)測試服務(wù)
telnet localhost hello
或者
telnet localhost 20001
22 apt 常用命令
sudo apt-cache show <package> 安裝的軟件包
sudo apt-get clean 清理所有apt下載的軟件緩存
sudo apt-get autoremove 自動卸載不需要的軟件包
sudo apt-get autoclean 清理舊版本的軟件緩存
23 dd 的常見應(yīng)用
(1) 克隆磁盤
dd if=/dev/sda of=/dev/sdb
(2) 將整張光盤轉(zhuǎn)化為 ISO 文件
dd if=/dev/cdrom of=/tmp/cdrom.iso bs=1024
裝載該 ISO 文件
mount -o loop -t iso9660 /tmp/cdrom.iso /mnt
(3) 備份 MBR
dd if=/dev/sda of=/boot/mbr_backup bs=512 count=1
(4) 還原 MBR
dd if=/boot/mbr_backup of=/dev/sda bs=446 count=1
(5) 制作一個 1GB 的交換文件
dd if=/dev/zero of=/swapfile bs=1024 count=1000000
加入并激活該交換文件
mkswap /swapfile && swapon /swapfile