How to modify the file character set in Linux

Source: Internet
Author: User
Tags exit character set

In some cases, we need to modify the character set of the file to resolve garbled or other problems. Under Linux, the operating system provides us with the Iconv command, so let's take a look at how this command is used.

[Root@oadata ~]# iconv--help  
usage: iconv [Options ...] [File ...]  
Converts the encoding of a given file.  
      
 input/Output format specification:-  
  F,--from-code= name     raw text encoding-  
  T,--to-code= name       output encoding  
      
 information:-  
  L,--list                 Enumerates all known character set  
      
 output controls:-  
  c                         ignores invalid characters from output-  
  o,--output=file          output file  
  -S,--silent               shutdown warning  
      --verbose              Print progress information  
      
  -?,--                 help gives the system assistance list  
      --usage                gives a brief usage information-  
  V,--version              Print Program version number  
      
Mandatory or optional arguments to long options are also mandatory or optional for any  
corresponding RT options.  
      
For bugs reporting instructions, please:  

If you want to view the character information for a file, Linux also provides the file function:

[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 don't prepend filenames to O  
                               Utput 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 is 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 ' match -L,--dereference causes Symlinks to is 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 O Rdinary ones--help Display this help and exit--version output version infor Mation and Exit [Root@oadata ~]# file-i a.log a.log:text/plain; Charset=us-ascii

Character set conversion for single file:

[Oracle@oadata dir1]$ ls-l  
Total 4  
-rw-r--r--1 Oracle oinstall 10-12 13:14 utf8.txt  
[Oracle@oadata dir1]$ fi Le-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  
Total 8  
-rw-r--r--1 Oracle Oinstall-10-12 13:43 gbk.txt-rw-r--r--  
1 Oracle Oinstall 10-12 13:14 utf8.txt [oracle@oadata dir1]$ file-i gbk.txt   
; gbk.txt:text/plain

To perform character set conversion on a file in a directory:

<pre name= "code" class= "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</pre><br><br>

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.