在 Debian(以及大多数 Linux 系统)中,“env 配置”通常指环境变量。导出的方式和场景不同,下面按常见需求给你整理一下。
env
或
printenv
env > env_backup.txt
如果只是想导出当前 shell 中自己 export 的变量:
export -p > env_export.sh
这个文件可以直接用:
source env_export.sh
env > before.txt
./your_program
env > after.txt
diff before.txt after.txt
/etc/environment
/etc/profile
/etc/profile.d/*.sh
/etc/bash.bashrc
~/.bashrc
~/.profile
~/.bash_profile
cp ~/.bashrc ~/bashrc_backup
cp /etc/environment ~/environment_backup
systemctl show <service_name> --property=Environment
# /etc/systemd/system/xxx.service
[Service]
Environment=VAR1=value1
EnvironmentFile=/etc/default/xxx
导出:
systemctl show -p Environment --value <service> > service_env.txt
docker exec <container> env > container_env.txt
| 目的 | 推荐方式 |
|---|---|
| 备份环境变量 | env > file |
| 在另一台机器复用 | export -p > env.sh |
| 调试程序环境 | env + diff |
| 系统配置备份 | 复制 /etc/environment 等 |
| 服务环境 | systemctl show |
如果你能具体说一下:
我可以给你更精确的命令。