Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 1130|回复: 0

Ubuntu环境变量,解压乱码,批量解压

  [复制链接]
  • TA的每日心情
    开心
    2023-3-18 00:22
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2013-3-11 22:17:37 | 显示全部楼层 |阅读模式
    环境变

    设置环境变量
    echo "export java_HOME=/usr/lib/JVM/java-6-openjdk-amd64/" >> ~/.bashrc
    echo 'export PATH=$PATHJAVA_HOME/bin' >> ~/.bashrc


    Session-wide environment variables
    Environment variable settings that should affect just a particular user (rather than the system as a whole) should be set into:
    • ~/.pam_environment - This file is specifically meant for setting a user's environment. It is not a script file, but rather consists of assignment expressions, one per line.

    PATH DEFAULT=${PATH}:${HOME}/MyPrograms
    Note: 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.
    If you are using KDE, see the KDE User-base page on this topic.
    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 variables
    Environment 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:
    • /etc/profile - This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over SSH), as well as by the DisplayManager when the desktop session loads. This is probably the file you will get referred to when asking veteran UNIX system administrators about environment variables. In Ubuntu, however, this file does little more than invoke the /etc/bash.bashrc file.
    • /etc/bash.bashrc - This is the system-wide version of the ~/.bashrc file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.

    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.

    更多详细见:EnvironmentVariables





    让环境变量即时生效: $ 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




    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-12-23 00:32 , Processed in 0.352070 second(s), 47 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表