LINUX修改檔案字元集

來源:互聯網
上載者:User

LINUX修改檔案字元集         有些情況下,我們需要修改檔案的字元集,以便解決亂碼或者其他問題。在linux下,作業系統為我們提供了ICONV這個命令,下面我們來看一下這個命令的具體使用方法。[plain] [root@oadata ~]# iconv --help  用法: iconv [選項...] [檔案...]  轉換給定檔案的編碼。     輸入/輸出格式規範:    -f, --from-code=名稱     原始文本編碼    -t, --to-code=名稱       輸出編碼     資訊:    -l, --list                 列舉所有已知的字元集     輸出控制:    -c                         從輸出中忽略無效的字元    -o, --output=FILE          輸出檔案    -s, --silent               關閉警告        --verbose              列印進度資訊      -?, --help                 給出該系統求助列表        --usage                給出簡要的用法資訊    -V, --version              列印程式版本號碼    Mandatory or optional arguments to long options are also mandatory or optional  for any corresponding short options.    For bug reporting instructions, please see: .          如果要查看某個檔案的字元資訊,linux同樣提供了file函數:[plain] [root@oadata ~]# file --help  Usage: file [OPTION]... [FILE]...  Determine file type of FILEs.      -m, --magic-file LIST      use LIST as a colon-separated list of magic                                 number files    -z, --uncompress           try to look inside compressed files    -b, --brief                do not prepend filenames to output lines    -c, --checking-printout    print the parsed form of the magic file, use in                                 conjunction with -m to debug a new magic file                                 before installing it    -f, --files-from FILE      read the filenames to be examined from FILE    -F, --separator string     use string as separator instead of `:'    -i, --mime                 output mime type strings    -k, --keep-going           don't stop at the first match    -L, --dereference          causes symlinks to be followed    -n, --no-buffer            do not buffer output    -N, --no-pad               do not pad output    -p, --preserve-date        preserve access times on files    -r, --raw                  don't translate unprintable chars to \ooo    -s, --special-files        treat special (block/char devices) files as                               ordinary ones        --help                 display this help and exit        --version              output version information and exit    [root@oadata ~]# file -i a.log  a.log: text/plain; charset=us-ascii   單檔案的字元集轉換:[plain] [oracle@oadata dir1]$ ls -l  總計 4  -rw-r--r-- 1 oracle oinstall 22 10-12 13:14 utf8.txt  [oracle@oadata dir1]$ file -i utf8.txt   utf8.txt: text/plain; charset=utf-8  [oracle@oadata dir1]$ iconv -f utf-8 -t gbk -o gbk.txt utf8.txt   [oracle@oadata dir1]$ ls -l  總計 8  -rw-r--r-- 1 oracle oinstall 15 10-12 13:43 gbk.txt  -rw-r--r-- 1 oracle oinstall 22 10-12 13:14 utf8.txt  [oracle@oadata dir1]$ file -i gbk.txt   gbk.txt: text/plain; charset=iso-8859-1   對某目錄下的檔案進行字元集轉換:[plain] for i in `find ./ -name *.php` ;   do echo $i;iconv -c -f gb18030 -t utf8 $i -o /tmp/iconv.tmp;  mv /tmp/iconv.tmp $i;   done 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.