Ubuntu日常技巧


我其实不算是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.bkjia.com/topicnews.aspx?tid=2

相关内容