Bri*_*ore 59 alias users bashrc
我有 Ubuntu 14.04.2。我想让所有用户自动拥有一组特定的别名。我在个人 .bashrc 中设置了别名,但我不想手动将它们复制到其他用户中。理想情况下,它也应该为新创建的用户自动设置这些。
0x2*_*fa0 74
您可以创建一个脚本/etc/profile.d/来为所有用户创建别名:
在以下位置创建一个名为00-aliases.sh(或任何其他花哨名称)的文件/etc/profile.d:
gksu gedit /etc/profile.d/00-aliases.sh
Run Code Online (Sandbox Code Playgroud)把你的别名放在这个文件中。例子:
alias foo='bar --baz'
alias baz='foo --bar'
Run Code Online (Sandbox Code Playgroud)保存文件
一些注意事项:
/etc/profile是一个全局文件,在~/.profile./etc/profile.d/ 是一个文件夹,其中包含由调用的脚本 /etc/profile当/etc/profile被调用(当你启动/登录一个shell),它搜索在结尾的文件.sh中/etc/profile.d/,并与这些命令之一运行它们:
source /etc/profile.d/myfile.sh
Run Code Online (Sandbox Code Playgroud)
. /etc/profile.d/myfile.sh
Run Code Online (Sandbox Code Playgroud)00-文件名放在文件名之前,使其在其余脚本之前执行。/etc/profile,但不建议这样做。tin*_*lyx 20
正如这里所指出的,最好在以下位置添加全局别名 /etc/bash.bashrc:
alias foo='bar --baz'
alias baz='foo --bar'
Run Code Online (Sandbox Code Playgroud)
,因为对于某些(非登录)shell可以忽略中的脚本/etc/profile.d。我花了几个小时才弄清楚为什么/etc/profile.d不起作用。
参见例如https://askubuntu.com/a/606882/和 理解 .bashrc 和 .bash_profile以了解shell 之间的区别。
别名仅在外壳内部时有效。如果你想要像可执行文件一样广泛访问的东西,你可以添加一个小的快捷脚本到/usr/bin,例如:
#!/bin/sh
ls -l "$@"
Run Code Online (Sandbox Code Playgroud)
在"$@"通过对可执行文件传递所有参数。脚本的名称将是可执行文件的名称。
来源:https : //unix.stackexchange.com/a/52509/15954