简体   繁体   English

linux:如何执行配置文件

[英]linux: how to execute profile file

My colleague gave me a file containing lots of configs such as 我的同事给了我一个包含许多配置的文件,例如

alias  ll="ls -l"
alias  lr="ls -lrt"
alias  gv="vim -g"

How can I use(execute) this profile? 我如何使用(执行)此配置文件?

You can load the profile using source command: 您可以使用source命令加载配置文件:

source <profile-filename>

eg: 例如:

source ~/.bash_profile

For your custom aliases, the best place should be at ~/.bash_aliases. 对于自定义别名,最佳位置应为〜/ .bash_aliases。 You must just be sure the ~/.bashrc file already contains the following lines: 您必须确保〜/ .bashrc文件已包含以下行:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

or in a more concise manner: 或者以更简洁的方式:

[ -f ~/.bash_aliases ] && . ~/.bash_aliases

To load them immediately, source it. 要立即加载它们,请将其获取。 Otherwise, aliases will be loaded at every terminal opening. 否则,将在每个终端开口处加载别名。 To check, use the alias command without argument. 要检查,请使用不带参数的alias命令。

You can put it in your local .bashrc (or appropriate shell rc file) file if you want it permanently. 如果您想永久保存它,可以将它放在本地.bashrc(或适当的shell rc文件)文件中。

cat fileNameProfile >> ~/.bashrc

And for current session: 对于本届会议:

source ~/.bashrc

If you want it just now, then: 如果你现在想要它,那么:

source fileNameProfile

For one time use, copy paste commands to your terminal:- 一次性使用,将粘贴命令复制到终端: -

alias  ll="ls -l"
alias  lr="ls -lrt"
alias  gv="vim -g"

For everytime use, add it in .bashrc. 对于每次使用,请将其添加到.bashrc中。

echo 'alias  ll="ls -l"' >>  ~/.bashrc
echo 'alias  lr="ls -lrt"' >> ~/.bashrc
echo 'alias  gv="vim -g"' >> ~/.bashrc

and then source ~/.bashrc 然后source ~/.bashrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM