In Linux, view the txt document. In Linux, view the txt document.
When we use the Windows operating system, the most commonly used text format may be txt. However, when we copy the txt text documents on the Windows platform to Linux, all the original Chinese characters are garbled. Yes, the reason for this result is that the default encoding format of the editor is different on the two platforms:
In the Window platform, the default Notepad encoding is ASCII code or GBK, and in the Linux platform is the default UTF-8 (Chinese environment ), different encoding causes Chinese characters in the original document to become garbled characters.
Solution:
Use the iconv command to convert the document encoding.
Iconv is not installed by default. The following describes how to install iconv:
1. Download:
Http://www.gnu.org/software/libiconv/#TOCdownloading
2. installation:
After the download is complete, switch to the download directory and unzip the package first:
$tar -xzvf libiconv-1.14.tar.gz
Then go to the decompressed file.
$cd libiconv-1.14_2
Check the README file, and we can see the installation steps: (of course, if you are familiar with the installation of source code, this step can be omitted ^-^)
$ ./configure --prefix=/usr/local$ make$ make install
3. Command Learning
After the tool is installed, you must first understand the usage of this command. There is nothing to say:
$iconv --help
We will see the following content:
Usage: iconv [OPTION...] [FILE...]Convert encoding of given files from one encoding to another. Input/Output format specification: -f, --from-code=NAME encoding of original text -t, --to-code=NAME encoding for output Information: -l, --list list all known coded character sets Output control: -c omit invalid characters from output -o, --output=FILE output file -s, --silent suppress warnings --verbose print progress information -?, --help Give this help list --usage Give a short usage message -V, --version Print program versionMandatory or optional arguments to long options are also mandatory or optionalfor any corresponding short options.
It is clear that the conversion is based on the following format:
Iconv-f original encoding-t target encoding file to be converted
4. encoding conversion:
After learning about encoding conversion, let's take an example to demonstrate:
$iconv -f gbk -t utf8 test.txt
After the command execution is complete, you will find that the Chinese characters in test.txt are normally displayed, but the original file is opened, but garbled. This is Easy. We can enter the output content into the file.
$iconv -f gbk -t utf8 test.txt -o test
Or run the following command:
$iconv -f gbk -t utf8 test.txt < test
Now we open the test file and we will find that the original Chinese characters are properly displayed ^-^
Note:
If there is no accident, the above installation steps may not be so smooth, the following error will be prompted during make:
n file included from progname.c:26:0:./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); ^make[2]: *** [progname.o] Error 1make[2]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib'make[1]: *** [all] Error 2make[1]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib'make: *** [all] Error 2
This software has a Bug. Google found a patch to solve the problem. The content is as follows:
--- srclib/stdio.in.h.orig 2011-08-07 16:42:06.000000000 +0300+++ srclib/stdio.in.h 2013-01-10 15:53:03.000000000 +0200@@ -695,7 +695,9 @@ /* It is very rare that the developer ever has full control of stdin, so any use of gets warrants an unconditional warning. Assume it is always declared, since it is required by C89. */-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");+#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)+ _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");+#endif #endif
PS: "+" in the content indicates the added content, and "-" indicates the deleted content!
You only need to perform the following operations to solve the problem:
1. Switch to the srclib directory:
$cd srclib
2. Modify the stdio. in. h file:
$gedit stdio.in.h
Locate the _ GL_WARN_ON_USE (gets, "gets is a security hole-use fgets instead") line by searching, and add Conditional compilation before and after the line, the modified content is as follows:
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");#endif
3. Save and exit, and then run make. make install to install ^-^.
References: http://forum.z27315.com/topic/15662-%E8%A7%A3%E5%86%B3%E7%BC%96%E8%AF%91libiconv%E6%97%B6%E7%9A%84gets-undeclared-here%E9%94%99%E8%AF%AF/
In Linux, how does one open a TXT file?
Nano <File Name> or
Vi <File Name>
It is mainly case sensitive and is recommended to use the former. The interface is friendly.
In linux, how does one view plain text documents in windows?
You can use wordpad to solve the line feed problem, but the encoding problem is hard to say. in linux, most of them are utf8, which is probably displayed in vista. The vista encoding is utf8, in the past, windows were both gb2312 and gb13080.