11 12
发新话题
打印

【求助】别名的预设文件在哪??

【求助】别名的预设文件在哪??

Mandriva2007的别名设置文件在哪?在登录后就有很多预先设置的别名和变量,但我却没找到设置这些别名的文件在哪。
各位大大有谁知道?:confused:      

TOP

您具体说说,我不是太明确您要改的文件或者变量类型      
Powered By Myself

TOP

就是alias那个命令,一般是在家目录下的.bash_profile文件进行设置的,如果要所有用户都能使用,好像可以在/etc/profile文件上设置。
而mdv2007也预设了很多别名,但是我却没有在上面的两个文件甚至是在家目录和/etc/目录下找到这些设置,不知道这些设置是放在哪?      

TOP

哦,我知道了,你不能改profile。

你看你的.bash_profile文件,对shell的 aliases脚本的定义:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

指明了要想 aliases ,必须参考~/.bashrc里面的东西。

所以,你可以将
alias hahahaha="ls -a" 这样的定义放在~/.bashrc里。这样,当前用户输入hahahaha就能ls -a。

全局用户的改法你住一看你当前用户的~/.bashrc里对默认脚本的定义:
# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

alias hahahaha="ls -a"



他是先考虑/etc/bashrc脚本,然后在考虑你后加的命令。

所以,修改全局用户的alias,要修改/etc/bashrc脚本,而不是profile,profile是shell的默认配置。      
Powered By Myself

TOP

明白
但是,那么系统中的默认设定在哪呢?
好像在命令行下输入alias就会显示出当前的别名设定,如
alias cd..='cd ..'
alias cp='cp -i'
alias d='ls'
alias df='df -h -x supermount'
.........
等等,但是在/etc/bashrc和在~/.bashrc下都找不到这些设定,不知道这些预设定是在哪个文件的?      

TOP

没有预设,所谓的ls,dir命令,实际上是系统中的一个程序,你把/bin/ls文件改名,改成bin/hahahaha,不用预设,输入hahahaha也能有ls的效果      
Powered By Myself

TOP

alias脚本会默认带着预设,当shell运行的时候,会考虑alias的脚本      
Powered By Myself

TOP

哦,原来这些都是alias的配置文件弄的~
那么这个文件在哪?      

TOP

在/etc/profile.d/alias.sh的脚本中有定义,就是你输入alias回车后的内容:

建议不要改这个脚本,很多程序调用了alias,你改了可能在你用源码安装一个软件的时候发生意想不到的错误。

[yigang@localhost ~]$ alias
alias cd..='cd ..'
alias cp='cp -i'
alias d='ls'
alias df='df -h -x supermount'
alias du='du -h'
alias grep='grep --color'
alias kde='xinit /usr/bin/startkde'
alias l='ls'
alias la='ls -a'
alias ll='ls -l'
alias ls='ls -F --show-control-chars --color=auto'
alias lsd='ls -d */'
alias mc='. /usr/share/mc/bin/mc-wrapper.sh'
alias md='mkdir'
alias mv='mv -i'
alias p='cd -'
alias rd='rmdir'
alias rm='rm -i'
alias s='cd ..'
[yigang@localhost ~]$      
Powered By Myself

TOP

明解,
hoho,谢谢~~      

TOP

 11 12
发新话题