我想缩短
sudo http_proxy="http://proxy:port" apt-get ______
到
sudo rep apt-get ________
这可以在 Ubuntu 中实现吗?
编辑:
所以我补充道
alias rapt-get="http_proxy="10.1.1.26:8080" apt-get"
到我的~/.bash_aliases
。我在这个文件中还有其他工作别名。
如果我在终端中输入 rapt-get,我会得到:
apt 0.8.16~exp12ubuntu10 for amd64 compiled on Apr 20 2012 10:19:39
Usage: apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 ...]
apt-get [options] source pkg1 [pkg2 ...]
apt-get
是一个简单的命令行界面,用于下载和安装软件包。最常用的命令是 update 和 install。
命令:
update - Retrieve new lists of packages
upgrade - Perform an upgrade
install - Install new packages (pkg is libc6 not libc6.deb)
remove - Remove packages
autoremove - Remove automatically all unused packages
purge - Remove packages and config files
source - Download source archives
build-dep - Configure build-dependencies for source packages
dist-upgrade - Distribution upgrade, see apt-get(8)
dselect-upgrade - Follow dselect selections
clean - Erase downloaded archive files
autoclean - Erase old downloaded archive files
check - Verify that there are no broken dependencies
changelog - Download and display the changelog for the given package
download - Download the binary package into the current directory
选项:
-h This help text.
-q Loggable output - no progress indicator
-qq No output except for errors
-d Download only - do NOT install or unpack archives
-s No-act. Perform ordering simulation
-y Assume Yes to all queries and do not prompt
-f Attempt to correct a system with broken dependencies in place
-m Attempt to continue if archives are unlocatable
-u Show a list of upgraded packages as well
-b Build the source package after fetching it
-V Show verbose version numbers
-c=? Read this configuration file
-o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp
See the apt-get(8), sources.list(5) and apt.conf(5) manual pages for more information and options.
This APT has Super Cow Powers. Seems to be working. But if i type `sudo rapt-get update`, I get
sudo: rapt-get: command not found
(抱歉,格式有问题,我通过手机浏览,看不到格式栏)
答案1
您还可以制作一个 sh 脚本,读取输入,将其插入命令并运行。我会为您上传一个这样的文件,但我无法访问我的电脑。
答案2
这也取决于你的/etc/sudoers
设置。首先,正如指出的那样,别名甚至在上下文中都不可用sudo
。但是,您可以调整别名以使其为:
alias rapt-get='http_proxy="10.1.1.26:8080" sudo apt-get'
即包含您为此调用设置的变量。如果您想sudo
从用户上下文中接管它,则必须进行编辑/etc/sudoers
以将变量名称添加到env_check
或 env_keep
设置。引用man sudoers
:
默认情况下,该选项处于启用状态。这会导致命令在包含、、、、、和以及调用进程的变量(由和选项允许)的最小 环境
env_reset
中执行。这实际上是环境变量的白名单。TERM
PATH
HOME
SHELL
LOGNAME
USER
USERNAME
env_check
env_keep
答案3
~/.bashrc
为你添加别名,并且只有你
sudo
以 root 身份运行。即使您具有管理员访问权限,您的用户也不是 root。
因此,将您的别名添加到~root/.bashrc
(通常是/root/.bashrc
)。
如果您想为所有用户添加此别名,请将其添加到/etc/profile