歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu日常技巧

Ubuntu日常技巧

日期:2017/2/28 15:51:14   编辑:Linux教程

我其實不算是SA,很多時候Ubuntu很多命令記不住。所以也就找一個地方記錄一下。長期更新。未來3個月,可能都要和ubuntu打交道。這個文檔,希望可以長期更新。

1:彩色查看log

如何可以做到看log,顯示的更好

需要安裝兩個包

apt-get install -y tmux ccze

這個時候就可以看log

tail -f /var/log/syslog | ccze

tail -f /var/log/squid/access.log | ccze


2:使用IPMItool

apt-get -y install ipmitool

2:加載IMPI

http://wiki.adamsweet.org/doku.php?id=ipmi_on_linux

modprobe ipmi_msghandler
modprobe ipmi_devintf
modprobe ipmi_si

這個時候就可以查看到ipmi的信息。

# ipmitool lan prinet

3:tasksel --list-tasks

ubuntu 安裝的時候,有一個軟件包的選擇。如果裝完以後,還想看到底有哪些軟件包的選擇呢?

# tasksel -h
Unknown option: h
Usage:
tasksel install <task>
tasksel remove <task>
tasksel [options]
-t, --test test mode; don't really do anything
--new-install automatically install some tasks
--list-tasks list tasks that would be displayed and exit
--task-packages list available packages in a task
--task-desc returns the description of a task

tasksel --list-tasks

這個就可以列出所有的組合。

到底裡面包含那幾個包呢?

tasksel --task-packages dns-server

The output of the command should list:
bind9-doc
bind9utils
bind9

如果希望安裝

tasksel install dns-server

4:搜索軟件

這是一個google搜索軟件的技巧,我經常使用,也就記錄在這裡。

httpd-2.2.8.tar.gz intitle:index

5:加載iso文件

mount -t auto -o loop /downloads/CentOS-6.2-x86_64-core.iso /mnt/

如果是光驅,那就簡單多

mount /dev/cdrom /mnt

6:查詢包

如果希望查詢源裡包的情況。當你不太清楚包的名字的情況下。

# apt-cache search openstack

7:查看服務器主板型號

服務器是超微的,不過我不知道具體型號是多少,也就無法升級。通過命令行是可以查看到。

# dmidecode |grep -A16 "System Information$"
System Information
Manufacturer: Supermicro
Product Name: X8DT3
Version: 1234567890
Serial Number: 1234567890
UUID: 3B703625-21C8-F25D-475C-0025902EF986
Wake-up Type: Power Switch
SKU Number: To Be Filled By O.E.M.
Family: 1234567890

Handle 0x0002, DMI type 2, 15 bytes
Base Board Information
Manufacturer: Supermicro
Product Name: X8DT3
Version: 2.0
Serial Number: OM16S33000
Asset Tag: 1234567890

8:VI裡替換

經常需要批量替換文本。我一般就只用全文替換。(參考http://apps.hi.baidu.com/share/detail/16718996)

:g/str1/s//str2/g

用字符串 str2 替換正文中所有出現的字符串 str1

9:dpkg用法

dpkg平常用的不多,不過還是很實用。

有時候需要確認某個文件是哪個軟件包裝上的。

# dpkg --search /etc/nova/nova.conf
nova-common: /etc/nova/nova.conf

查看已經安裝包的情況

dpkg --status nova-common

列出已經安裝的包

#dpkg --list

要想統計一下已經安裝包的數量

#dpkg --list | wc -l

10 : 全文搜索

這個經常要用到,搜索/etc 目錄下,找配置文件,兩個命令,達到相同的效果。

# grep -lr "NOVA_API_KEY" /opt/stack/

# find /opt/stack | xargs grep "NOVA_API_KEY"

11:查看端口

這個命令我老是記不住

ps aux | grep vnc

12: apt-get 安裝的包存放在哪裡?
默認ubuntu安裝完的包是保存在
/var/cache/apt/archives
你可以備份這個目錄,下次安裝,就不需要聯網,直接從這裡安裝
如果要清除緩存文件夾,可以執行
sudo apt-get clean

13: VI很難使用?

默認vi,用起來是很不爽。你需要安裝vim,就好很多。ubuntu12.04,你只需要裝完vim就可以。用vi打開文件,就會顯示顏色。

14:設置靜態IP地址

一個例子,設置靜態IP,默認經常都是dhcp。

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 172.16.10.51
netmask 255.255.0.0
network 172.16.0.0
broadcast 172.16.255.255
gateway 172.16.10.1
# dns-* options are implemented by the resolvconf package, if installed
dns-search test.com

更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved