长弓无敌
===========================================================
Debian 技巧收集
===========================================================

How to change the hostname?

/bin/hostname newcomputername;


How to change the ip in Debian?

  • advanced method:
$ifdown eth0
$vi /etc/network/interfaces
$ifup eth0
In this file, we can change the ip, netmask, gateway and DNS;
  • Basic Method
 # ifconfig eth0 inet down
# ifconfig eth0 inet up 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255
# route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.0.1 dev eth0
# ifconfig
# route

Change the DNS of network configuration?

vi /etc/resolv.conf

How to change the screen resolution?

If the graphic system choose XServerFree86 then
vi /etc/X11/XFree86-4

If choose XORG then

 vi /etc/X11/xorg.conf

change gateway?

Delete the exsited gateway, use:

/sbin/route del default gw 192.168.1.1

Add new gateway, use:

/sbin/route add default gw 192.168.1.100

After we change the network configuration, we should reboot the computer to let the network work correct.

Install new softwares?

Use synaptic to manage the softwares;
#apt-get install synaptic

Or use another software:

#apt-get install aptitude
#aptitue search cvs (to look for the softwares related to CVS)

How to see the tree view of a diretory?

use command 'tree'
#apt-get install tree
#tree dirctoryname -o dir.txt

How to add line number to a file?

 cat -b filename > filewithnumber

How to see the size of a file or directory?

du -sh filename

How to add line number to a file?

$cat -n filename
or
$awk '{print NR, $0}' filename

args in AWK?

  1. $0 means the whole record, usually a line;
  2. $n means the n-th field of a record;

how to change the numbers in colunm to a line?

awk '{printf("%s,",$1)}' filename

How to de/compress the files?

tar cvf file.tar file/

If the file is .tar.gz then use the command to decompress;

tar zxvf file.tar.gz

Another method:

tar jcvf file.tar file/

then the compressed file will be ××.bz; and we can decompress it with the command:

tar xvf *.tar.bz

find and delete the files?

find /dir -name "nohup.out" -exec rm {} ;

find /dir -name "nohup.out"|while read i;do >$i;done

How to batch rename files?

Build a shell script name rename, the content like this:

#!/usr/local/bin/perl5.8 -w
use strict;

# usage: rename perlexpr [files]

(my $regexp = shift @ARGV) or die "usage: rename perlexpr [filenames]n";

if (!@ARGV) {
@ARGV=;
chomp(@ARGV);
}

foreach $_ (@ARGV) {
my $old_name = $_;
eval $regexp;
die $@ if $@;
rename($old_name, $_) unless $old_name eq $_;
}

exit(0);

then use regular express method to rename files;

rename s/str1/str2/ batchfiles
If there are some special string like "?" then we can use command like this:
rename s/'?'/strreplace/ *.files

Another method use shell, Use basename function:

# rename every *.htm file *.html
for f in *htm ; do mv $f `basename $f htm`html; done

Another method use SED:

# change .htm files to .html
for file in *.htm ; do mv $file `echo $file | sed 's/(.*.)htm/1html/'` ; done
# change .html files to .htm
for file in *.html ; do mv $file `echo $file | sed 's/(.*.)html/1htm/'` ; done
#change .html files to .shtml
for file in *.html ; do mv $file `echo $file | sed 's/(.*.)html/1shtml/'` ; done
#change .html files to php
for file in *.html ; do mv $file `echo $file | sed 's/(.*.)html/1php/'` ; done

Network configuration

在/etc/network/interfaces中设置网卡接口 ,不管是静态IP还是DHCP, 需重起网络设置方可生效
#/etc/init.d/networking restart

相关文件还有/etc/hosts,
/etc/resolv.conf (修改后立即生效)

服务加载

根据自己的习惯选用下列工具之一:

*rcconf
有时可能需要执行update-rcconf-guide以更新所能管理的服务脚本

*sysv-rc-conf

*sysvconfig

临时启动或停止系统服务:
#/etc/init.d/*servicescript* {start|stop|restart}

关于tab

好,跟帖,不灌纯净水
还有,非要是Debian的么?跟个bash操作的先。

在.bashrc里面添加如下三行(如果是新装的系统,去掉.bashrc的最后三行的注释就成)
代码:

if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi

立刻让你的TAB键自动完成功能强大非凡,不过也会有小小的副作用 :-)

在你的.inputrc文件里面加上如下两行
代码:

"e[A": history-search-backward "e[B": history-search-forward

能够让你在命令行输入字符之后,就可以用方向键Up,Down来搜索以该串字符开头的历史命令(偷自Carlos的Blog,想了解更多信息,请man readline)

在.bashrc中加入如下两行:
代码:

HISTCONTROL=ignoredups HISTIGNORE='ls:pwd:cd:clear:vim:fg:bg:jobs:top'

你的命令行历史记录里面就不会有HISTIGNORE中列出的那些无聊命令(可以自行添加)

alias 命令可以为一些常用的比较长的命令输入用较短的名字,像如果在.bashrc 里面加入:
alias ls='ls --color'
这样在输入ls时就可以有彩色的显示了,不过除非你是有意的,别名尽量避免系统中本来存在的命令哦。

清除孤立包

$deborphan --guess-all|tr ["n"] [" "]|sudo xargs apt-get remove --purge - -y

查看进程调用

 lsof -p <pid>

apt 小技巧

$ cat /etc/apt/apt.conf
APT::Default-Release "testing";
APT::Get::Show-Upgraded "true";
APT::Get::Show-Versions "true";
APT::Get::Purge "true";

开机自动打开 数字键盘

打开 /etc/console-tools/config, 文件尾部找到:

# Turn on numlock by default
LEDS=+num <== 取消此行的注释

查找问题所在

$strace -f -F -o outfile <cmd>

优化安装源

#apt-get install apt-spy
#mv sources.list sources.list.bak //backup
#man apt-spy //获取详细的使用方法
#apt-spy update //更新您的镜像列表文件 /var/lib/apt-spy/mirrors.txt
# apt-spy -d testing -a Asia
//在亚洲区寻找速度最快的testing版镜像,并生成 sources.list文件,也可使用 -o 参数指定写入文件

rar 解压缩

rar e *.rar //解压缩到一个目录
rar x *.rar //按照多个目录进行解压缩

修改时间

root@0[wide288]# date
日 11月 13 16:57:34 CST 2005
root@0[wide288]# date 11131646
日 11月 13 16:46:00 CST 2005
root@0[wide288]# date
日 11月 13 16:46:04 CST 2005

或者
设置日期
HTML 代码:

设置时间
HTML 代码:

写入CMOS
HTML 代码:

hwclock --systohc


读取CMOS时间
HTML 代码:

hwclock --hctosys

请问能否用tar命令行解压包中特定文件名的文件?

引用:
作者: ys_freedom


PHP 代码:
colinux:~/test# ls
test.tar
colinux:~/test# tar -tvf test.tar
drwxr-xr-x root/root 0 2005-11-17 10:13:37 ./
-rw-r--r-- root/root 16 2005-11-17 10:12:55 ./test2
-rwxr-xr-x root/root 89 2005-11-10 03:23:37 ./test.sh
colinux:~/test# tar --get -vf test.tar test.sh
tar: test.sh: Not found in archive
tar: Error exit delayed from previous errors
colinux:~/test# tar --get -vf test.tar ./test.sh
./test.sh
colinux:~/test# ls -l
total 16
-rwxr-xr-x 1 root root 89 Nov 10 03:23 test.sh
-rw-r--r-- 1 root root 10240 Nov 17 10:13 test.tar

不同控制台间切换

HTML 代码:

ALT+ ←



HTML 代码:

ALT+ →


指定控制台切换
HTML 代码:

ALT+Fn(n:1~7)



控制台下滚屏
HTML 代码:

SHIFT + pageUp/pageDown

给定关键字, 查找相关命令

HTML 代码:

apropos keyword

HTML 代码:

man -k keyword

查找文件

#updatedb
$locate filename

系统服务

1.编写启动脚本, 并将其置于 /etc/init.d/目录下

2. 付予 可执行权限

3. 设定为启动服务

#/usr/sbin/update-rc.d <shell name> defaults

4.将其删除

#/usr/sbin/update-rc.d -f <shell name> remove

5.根据运行级别设定,例如

#/usr/sbin/update-rc.d <shell name> start 20 1 2 3 . stop 20 4 5 .

用lftp显示服务器提示信息

lftp 缺省不会显示 ftp 服务器的欢迎信息和错误信息,可以在 ~/.lftprc 里写入一行

HTML 代码:

debug 3

固定软件包版本

保持软件包的一个版本
HTML 代码:

#aptitude hold package_name


解除
HTML 代码:

#aptitude unhold package_name

ftp编码

set ftp:charset gbk
set file:charset utf8

需要漂亮的 ASCII 艺术字吗?

试试 FIGlet
详细使用说明:
HTML 代码:

man figlet

如何启动进入文本模式

HTML 代码:

# update-rc.d -f ?dm remove //?=k,g,x

查找哪个文件在哪个包里,不管有没有安装

代码:

wajig whichpkg libgtk-1.2



重新启动gdm
代码:

wajig restart gdm


在apt-get.org 上搜索包,列出其源
代码:

wajig findpkg emelfm2

控制台快照

可以用setterm程序来获得控制台下的屏幕截图。命令格式为:
HTML 代码:

setterm -dump 1

使用 gdm 实现自动登录

/etc/gdm/gdm.conf
HTML 代码:

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=tony

禁用ipv6

/etc/modprobe.d/aliases
HTML 代码:

#alias net-pf-10 ipv6 alias net-pf-10 off

modconf 移除 ipv6模块

调查看硬件信息

HTML 代码:

apt-get install lshw && lshw

freebuffer and Grub

由于需要fb支持
所以在/boot/grub/menu.lst里
加入 vga=788(或其它)

useradd 与 adduser

引用:
useradd应该是源于unix的命令,passwd包提供.
使用时需要明确指定参数,不会自动创建家目录和对应组,
仅仅操作/etc/passwd和/etc/shadow
对应 userdel

引用:
adduser是一个交互shell脚本,发行版相关.同名包提供.
自动创建创建家目录和对应组, 引用/etc/skel/配置.
在命令执行过程中会调用 useradd.
对应deluser

修改用户资料

chfn userid

解决 apt-get 更新的 W: There are no public key available for the following key IDs: 010908312D230C5F 警告

HTML 代码:

$ wget http://ftp-master.debian.org/ziyi_key_2006.asc
$ sudo apt-key add ziyi_key_2006.asc

解决wu-ftp连接过慢的方法

进入/etc/xinetd.d/wu-ftp,将

  log_on_success += DURATION USERID
  log_on_failure += USERID

两行删掉,然后重起xinetd,好了,问题解决!

检测nvidia显卡

~$glxgears
~$ glxinfo | grep rendering

将网卡标识与mac绑定

auto lo eth0 eth1
iface lo inet loopback
mapping eth0 eth1

map 00:37:E9:17:64:AF netA
map 00:21:E9:17:64:B5 netB

iface netA inet static address etc...
iface netB inet static address etc...

移除无用的locale files文件

引用:
localepurge

apt-get update 抛出错误

HTML 代码:

Dynamic MMap ran out of room

原因:是apt的cache 太小了

解决:在/etc/apt/apt.conf中加入:
HTML 代码:

APT::Cache-Limit "10000000";

其中 10000000=10M

partial 文件被误删

错误:
HTML 代码:

/var/cache/apt/archives/partial is missing

原因:partial 文件被误删
解决:重建即可
HTML 代码:

#mkdir -p /var/cache/apt/archives/partial

系统更新

HTML 代码:

apt-get update apt-get upgrade/dist-upgrade aptitude update aptitude upgrade/dist-upgrade

设置屏幕分辨率和刷新率

dpkg-reconfigure xserver-xorg
还不行的话,继续
apt-get install xdebconfigurator
xdebconfigurator


调整分辨率和刷新率

#aptitude install xdebconfigurator

#xdebconfigurator
获取硬件信息

根据所得信息调整/etc/X11/xorg.conf中的参数

Grub的恢复

如果霸道的windows破坏了你的grub,你不必着急,几个简单的步骤就可以恢复它。

安装环境:IBM6824 hda1 Fedora 1.0 hda2 winxp

方法一:如果你有boot盘

1: 用 Fedora boot 盘引导
2:进入linux系统,进入命令行状态,
3:#grub回车,
4:grub>root (hdx,y) 回车 ,
5:grub>setup (hd0)回车,显示成功信息,
6:grub>quit回车,
退出。ok!

方法二:如果你没有boot盘,你可以用安装光盘。

1.在BOIS中把系统用光驱来引导,把安装盘的第一张放到光驱,重启。
2.等安装界面出来后,按[F4]键,也就是linux rescue模式。
3.一系列键盘以及几项简单的配制,过后就[继续]了
4.然后会出现这样的字符 sh#
:#grub回车,
4:grub>root (hdx,y) 回车 ,
5:grub>setup (hd0)回车,显示成功信息,
6:grub>quit回车,
退出。ok!

这里的X,如果是一个盘,就是0,如果你所安装的linux的根分区在
第二个硬盘上,那X就是1了;Y,就是装有linux系统所在的根分区。
setup (hd0)就是把GRUB写到硬盘的MBR上。

OK,reboot,我们的双系统又来了。

改变默认浏览器

update-alternatives --config mozilla

改变Windows Manager

update-alternatives --config x-window-manager

Debian中Grub安装和修改Grub启动时的背景图片简单步骤

#########grub
1 apt-get install grub
2 grub-install /dev/hda
3 update-grub
4 reboot
#########修改grub启动时的背景图片
1 将一图片转化成640*480,14色的XPM文件:
#convert abc.jpg -colors 14 -geometry 640x480! abc.xpm
2 压缩生成的xpm文件,使用gzip
#gzip -9 abc.xpm
3 将abc.xpm.gz拷到/boot/grub下
4 修改/boot/grub/menu.lst
splashimage /boot/grub/abc.xpm.gz
5 存盘退出
junsheng 发表于:2006.08.01 17:46 ::分类: ( Linux ) ::阅读:(1270次) :: 评论 (0)

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)

 authimage


自我介绍
切换风格
新闻聚合
博客日历
文章归档...
最新发表...
最新评论...
最多阅读文章...
最多评论文章...
博客统计...
Blog信息
网站链接...