TA的每日心情 | 开心 2023-3-18 00:22 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
环境变量
设置环境变量
echo "export java_HOME=/usr/lib/JVM/java-6-openjdk-amd64/" >> ~/.bashrc
echo 'export PATH=$PATHJAVA_HOME/bin' >> ~/.bashrc
Session-wide environment variablesEnvironment variable settings that should affect just a particular user (rather than the system as a whole) should be set into: PATH DEFAULT=${PATH}:${HOME}/MyProgramsNote: Using .pam_environment requires a re-login in order to initialize the variables. Restarting just the terminal is not sufficient to be able to use the variables. Not recommended anymore: ~/.profile - In this file you can also place environment variable assignments, since it gets executed automatically by the DisplayManager during the start-up process desktop session as well as by the login shell when one logs-in from the textual console. ~/.bash_profile or ~/.bash_login - If one of these file exist, bash executes it rather than "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default. ~/.bashrc - Because of the way Ubuntu currently sets up the various script files by default, this may be the easiest place to set variables in. The default configuration nearly guarantees that this file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. The performance cost of this will be negligible; the overhead of forking and execing bash will massively dominate the small cost of setting a handful of variables.
System-wide environment variablesEnvironment variable settings that affect the system as a whole (rather than just a particular user) should not be placed in any of the many system-level scripts that get executed when the system or the desktop session are loaded, but into /etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.
Not recommended: Note: Any variables added to these locations will not be reflected when invoking them with a sudo command, as sudo has a default policy of resetting the Environment and setting a secure path (this behavior is defined in /etc/sudoers). As a workaround, you can use "sudo su" that will provide a shell with root privileges but retaining any modified PATH variables. Note: When dealing with end-user/home desktop systems may be appropriate to place settings in the user's ~/.pam_environment files discussed above rather than the system-wide ones, since those files do not require one to utilize root privileges in order to edit and are easily moved between systems. Note: Some systems now use an envvar.sh placed in the /etc/profile.d/ directory to set system wide environment strings.
让环境变量即时生效: $ source /etc/environment
linux让环境变量即时生效
1.立即生效:使用source命令! 例 : source .bashrc 就会立即生效了…… 注释: source命令用法:
source FileName
作用:在当前bash环境下读取并执行FileName中的命令。
注:该命令通常用命令“.”来替代。
如:source .bashrc 与 . .bashrc 是等效的。 2. 嘿嘿,重启吧,这个肯定可以生效的
临时解决ubuntu解压windows生成的zip文件时乱码问题有2种方式解决问题:
1. 通过unzip行命令解压,指定字符集
unzip -O CP936 xxx.zip (用GBK, GB18030也可以)
有趣的是unzip的manual中并无这个选项的说明, unzip --help对这个参数有一行简单的说明。
2. 在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件
/etc/environment中加入2行
UNZIP="-O CP936"
ZIPINFO="-O CP936"
批量解压zip文件解压有乱码的zip文件
方法一:
unzip -O GBK mycpmpressfile.zip (用CP936, GB18030也可以)
方法二:
sudo apt-get install p7zip-full convmv
LANG=C 7z x abc.zip
convmv -f cp936 -t utf8 -r --notest *
方法三:
在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件/etc/environment中加入2行
UNZIP="-O CP936"
ZIPINFO="-O CP936"
方法四:
写一个脚本程序,保存成unzipgbk.py
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
print "rocessing File " + sys.argv[1]
file=zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
utf8name=name.decode('gbk')
print "Extracting " + utf8name
pathname = os.path.dirname(utf8name)
if not os.path.exists(pathname) and pathname!= "":
os.makedirs(pathname)
data = file.read(name)
if not os.path.exists(utf8name):
fo = open(utf8name, "w")
fo.write(data)
fo.close
file.close()
批量解压zip
方法一:
for i in *.zip;do unzip $i;done
方法二:
find -iname "*.zip" -execdir unzip {} +
find -iname "*.zip" -exec unzip {} \;
方法三:
ls *.tar.gz | xargs -n1 tar xzvf
方法四:
for i in $(ls *.gz);do tar xvf $i;done
方法五:
tar xvf '*.tar.gz' //因为tar不支持通配符语法,加上引号让shell解析通配符
批量解压并解决文件名乱码
方法一:
unzip -O CP936 '*.zip'
方法二:
for i in *.zip;do unzip -O CP936 $i;done
|
|