[分享]大家贴一下自己常用,喜欢的 alias 吧 :)

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

[分享]大家贴一下自己常用,喜欢的 alias 吧 :)

#1

帖子 iblicf » 2007-08-12 12:09

※ linux 命令通常都要跟一些参数执行,如果每次都是手动的添加就显得麻烦了,有的也不好记 . linux 可以通过( alias )别名的功能来减少你的输入 , alias 一般放在 .bashrc 文件里 ,. 使用别名能提高工作效率,下边是我常用的一些alias, 我会大致解释一下, 我希望大家能贴出自己喜欢常用的alias , 也稍作解释,分享一下 : )


alias ls='ls -S -ho --color=auto'
-S 用来按文件大小排序的

alias ld='ls -l |grep "^d"'
这个是只列出目录,因为我发现 ls -d 似乎不象manpage里边描述的那样工作

alias km='fuser -k /usr/bin/mplayer'
fuser -k 也是用来杀进程的,(kill 跟某个文件有关的进程), mplayer 经常死,如果用 ps 查进程号再杀,显得罗嗦了, fuser -k 就很方便

alias kd='fuser -k /home/weiyh/software/mldonkey-2.9.0/mlnet'
同理,我设置 sancho 退出不 kill core ,,我想用 sancho 的一些gui方便, 我也想 mldonkey 在后台运行节约资源, 如果我想暂时停掉 mldonkey ,比如要用其他bt了,要apt-get update 了, fuser -k , kill 掉 mlnet

alias shut='sudo poweroff -f'
这个我用来快速关机

alias cman='man -M /home/weiyh/readings/zh_CN1'
这个是我的中文man手册

alias ce='compiz --replace -c emerald & >&/dev/null'
这个是启用compiz fussion , 第一个 "&" 是后台运行,第 2 个 "&" 是为了不显示提示,错误什么的


alias q='amixer -c 0 set PCM 6dB+ 1>/dev/null'
alias z='amixer -c 0 set PCM 6dB- 1>/dev/null'

gnome下调节音量不太方便,如果你说可以用鼠标滚轮,是的,不过那只能调节 master 主声道的音量,gnome 快捷方式也是 .... 许多播放器,比如 mplayer / audacious 它们直接改的是 PCM 声道, 要想调节PCM就得双击那个喇叭,很慢的调出来一个窗口,我这里经常是 ( 3-5秒 ), 我是个键盘主义者,试验了一下,找到了命令行方式,q +6分贝,z -6分贝,步进值可以改 , 好了,这样就简单了


分享,分享,你的经验教给别人,别人有了收获,你也没有损失什么 ....
:em01 :em52 :em70
上次由 iblicf 在 2007-08-12 15:33,总共编辑 2 次。
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#2

帖子 xhy » 2007-08-12 12:27

alias df='df -t ext3'
alias grep='grep --colour=auto'
alias ls='ls --color=auto'
目前负债150多万
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

#3

帖子 iblicf » 2007-08-12 12:33

谢谢,,df -t ext3 只列出 ext3 也就是linux 分区的使用情况, grep --colour=auto 也不错,,我建议你再加上 -r 递归 :) ....

麻烦大家加上简短说明阿,,谢谢了 !!!
上次由 iblicf 在 2007-08-12 15:35,总共编辑 1 次。
头像
yhlfh
帖子: 579
注册时间: 2006-09-02 20:42
来自: 东海明珠

#4

帖子 yhlfh » 2007-08-12 13:37

代码: 全选

alias emacs='emacs -nw'
由于我装的emacs是带图形界面的,而我在命令行下编辑时不希望打开窗口,所以就加了这样一个选项。如果想开窗口,可以用emacs22或指定全路径。
上次由 yhlfh 在 2007-08-25 8:21,总共编辑 2 次。
Life is like a box of chocolates, you never know what you're going to get.
leeyee
帖子: 723
注册时间: 2006-04-11 9:01

#5

帖子 leeyee » 2007-08-12 13:52

代码: 全选

alias acpi='acpi -V'
I would love to change the world, but they won't give me the source code.
http://hi.baidu.com/wienerlee
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#6

帖子 millenniumdark » 2007-08-12 14:57

加精。
头像
vvoody
帖子: 749
注册时间: 2007-01-21 20:10

#7

帖子 vvoody » 2007-08-12 15:02

yhlfh 写了:alias emacs='emacs -nw'
奇怪
vvoody@ubuntu:~$ emacs -nw
emacs: Cannot open termcap database file
头像
hualang0929
帖子: 1226
注册时间: 2006-11-11 10:23
来自: Mars
联系:

#8

帖子 hualang0929 » 2007-08-12 16:22

alias la='ls -lha'
alias ll='ls -lh'
alias ls='ls --color=auto'
alias lu='ls /dev/disk/by-uuid -l'

alias gj='sudo shutdown -h now'
alias cq='sudo shutdown -r now'

alias lx='sudo linux1x -d'
alias xz='sync & fuser -km /media/disk'
alias sk='sudo killall'

alias td='tar --delete -f '
alias tl='tar tf '
alias tu='tar uPvf '
alias tx='tar xPvf '
alias tn='tar cPvf'

alias cman='man -M /usr/share/man/zh_CN/'

alias aup='sudo aptitude update'
alias ag='sudo aptitude upgrade'
alias adg='sudo aptitude dist-upgrade'
alias arm='sudo aptitude remove'
alias ai='sudo aptitude install'
alias ari='sudo aptitude reinstall'
alias aac='sudo aptitude autoclean'
alias ase='aptitude search'
alias ash='aptitude show'

alias ustc='telnet bbs.ustc.edu.cn'
alias ngpx='telnet bbs.gdut.edu.cn'

alias cn='export LC_ALL=zh_CN.UTF-8'
alias en='export LC_ALL=C'

alias synoff='synclient touchpadoff=1'
alias synon='synclient touchpadoff=0'
抬头望星空一片晴,我独行,夜已渐寒……
头像
huyang163
帖子: 71
注册时间: 2007-08-03 17:06

#9

帖子 huyang163 » 2007-08-14 16:46

先收藏,正在学习中
头像
boydd
帖子: 255
注册时间: 2007-05-10 19:42
来自: 南京, Deutschland, Karlsruhe
联系:

#10

帖子 boydd » 2007-08-15 6:20

我不推荐使用alias grep='grep --colour=auto'
可以另外设置一个
alias grepcolor='grep --colour=auto'
原因是
比如
ls | grep jpg | xargs -i -t mv {} ../
时会报错找不到文件,原因就是因为添加了颜色,所以终端中的文本被改变了
头像
laborer
帖子: 1016
注册时间: 2005-10-25 11:15
联系:

#11

帖子 laborer » 2007-08-15 6:34

gnome下调节音量不太方便,如果你说可以用鼠标滚轮,是的,不过那只能调节 master 主声道的音量,gnome 快捷方式也是 ....
你说的这两个都可以分别控制是master还是pcm的。
hreiser@oakland:~$ killall -9 wife
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

#12

帖子 iblicf » 2007-08-15 15:06

boydd 写了:我不推荐使用alias grep='grep --colour=auto'
可以另外设置一个
alias grepcolor='grep --colour=auto'
原因是
比如
ls | grep jpg | xargs -i -t mv {} ../
时会报错找不到文件,原因就是因为添加了颜色,所以终端中的文本被改变了
这个是要 mv *.jpg ../ ?

laborer:
你说的这两个都可以分别控制是master还是pcm的。
是可以的,,就是界面上用鼠标只能比较方便的调节master,调节pcm 还得打开一个对话框,, 而pcm音量经常被媒体播放器改动了,我觉得还是类似快捷键方便点,
头像
boydd
帖子: 255
注册时间: 2007-05-10 19:42
来自: 南京, Deutschland, Karlsruhe
联系:

#13

帖子 boydd » 2007-08-15 15:11

这个是要 mv *.jpg ../ ?
只是举个例子,还可以做更复杂的东西,如
ls | grep tiff | sed 's\tiff\\g' | xargs -p -i -t convert {}tiff {}pgm[/quote]
头像
yhlfh
帖子: 579
注册时间: 2006-09-02 20:42
来自: 东海明珠

#14

帖子 yhlfh » 2007-08-25 8:16

代码: 全选

alias ls='ls --color=auto --human-readable'
:D
这个--human-readable选项让ls显示普通人能够看懂的文件大小,就是显示成几K、几M、几G。
----
另外,这么多alias全部写到 .bashrc 里,.bashrc文件会变得很乱,建议专门新建一个 .bash_aliases 文件用来放alias,然后在 .bashrc 中加入以下代码:

代码: 全选

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
这样你就可以无所顾虑地在 .bash_aliases 里加入你的alias了,想加多少就加多少。 :wink:
Life is like a box of chocolates, you never know what you're going to get.
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

#15

帖子 iblicf » 2007-08-25 8:50

human 那个 -h 就行了, alias 多了乱倒是不乱,稍微影响点 terminal 的启动速度
回复