linux下查看文件编码及修改编码

express中文乱码解决 中文乱码解决。。。。。。。。。。。。。。。。。。。 立即下载
 

查看文件编码
在Linux中查看文件编码可以通过以下几种方式:
1.在Vim中可以直接查看文件编码
:set fileencoding
即可显示文件编码格式。
如果你只是想查看其它编码格式的文件或者想解决用Vim查看文件乱码的问题,那么你可以在
~/.vimrc 文件中添加以下内容:

set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936

这样,就可以让vim自动识别文件编码(可以自动识别UTF-8或者GBK编码的文件),其实就是依照 fileencodings提供的编码列表尝试,如果没有找到合适的编码,就用latin-1(ASCII)编码打开。
2. enca (如果你的系统中没有安装这个命令,可以用sudo yum install -y enca 安装 )查看文件编码
$ enca filename
filename: Universal transformation format 8 bits; UTF-8
CRLF line terminators
需要说明一点的是,enca对某些GBK编码的文件识别的不是很好,识别时会出现:
Unrecognized encoding

文件编码转换
1.在Vim中直接进行转换文件编码,比如将一个文件转换成utf-8格式
:set fileencoding=utf-8

2. enconv 转换文件编码,比如要将一个GBK编码的文件转换成UTF-8编码,操作如下
enconv -L zh_CN -x UTF-8 filename

3. iconv 转换,iconv的命令格式如下:
iconv -f encoding -t encoding inputfile
比如将一个UTF-8 编码的文件转换成GBK编码
iconv -f UTF-8 -t GBK file1 -o file2

查看文件编码file命令
file ip.txt  ip.txt: UTF-8 Unicode text, with escape sequences
一、利用iconv命令进行编码转换文件内容编码转换  iconv命令用于转换指定文件的编码,默认输出到标准输出设备,亦可指定输出文件。  用法: iconv [选项...] [文件...]  有如下选项可用:  输入/输出格式规范:  -f, --from-code=名称 原始文本编码  -t, --to-code=名称 输出编码  信息:  -l, --list 列举所有已知的字符集    输出控制:  -c 从输出中忽略无效的字符  -o, --output=FILE 输出文件  -s, --silent 关闭警告  --verbose 打印进度信息  -?, --help 给出该系统求助列表  --usage 给出简要的用法信息  -V, --version 打印程序版本号    例子:  iconv -f utf-8 -t gb2312 aaa.txt >bbb.txt  这个命令读取aaa.txt文件,从utf-8编码转换为gb2312编码,其输出定向到bbb.txt文件。
二、文件名编码转换
因为现在用linux,原来在windows里的文件都是用GBK编码的。所以copy到linux下是乱码,文件内容可以用iconv来转换可是好多中文的文件名还是乱码,找到个可以转换文件名编码的命令,就是convmv。
convmv命令详细参数  例如
convmv -f GBK -t UTF-8 *.mp3
不过这个命令不会直正的转换,你可以看到转换前后的对比。如果要直正的转换要加上参数 --notest
convmv -f GBK -t UTF-8 --notest *.mp3
-f 参数是指出转换前的编码,-t 是转换后的编码。这个千万不要弄错了。不然可能还是乱码哦。还有一个参数很有用。就是 -r 这个表示递归转换当前目录下的所有子目录。
* 需要安装 convmv-1.10-1.el5.noarch.rpm  
三、  更好的傻瓜型命令行工具enca,它不但能智能的识别文件的编码,而且还支持成批转换。    1.安装    
$sudo apt-get install enca    
2.查看当前文件编码    
enca -L zh_CN ip.txt     Simplified Chinese National Standard; GB2312     Surrounded by/intermixed with non-text data    
3.转换    命令格式如下    
$enca -L 当前语言 -x 目标编码 文件名    
例如要把当前目录下的所有文件都转成utf-8    
enca -L zh_CN -x utf-8 *     
检查文件的编码 enca -L zh_CN file     
 将文件编码转换为"UTF-8"编码  enca -L zh_CN -x UTF-8 file
如果不想覆盖原文件可以这样         enca -L zh_CN -x UTF-8 < file1 > file2 
基于SpringBoot 3 + Vue 3的全栈民宿预约管理系统设计与实现 文章将详细阐述系统的需求分析、架构设计、数据库设计、核心功能模块的实现(包括用户认证、房源管理、订单流程、支付集成等),并提供关键代码片段,最后对系统进行总结与展望。.requestMatchers("/api/admin/**").hasRole("ADMIN") // 管理员接口。.requestMatchers("/api/auth/**").permitAll() // 认证接口公开。.requestMatchers("/api/public/**").permitAll() // 公开资源。 阅读详情

相关推荐

保姆级避坑指南:在Ubuntu 22.04上从零编译Autoware.universe(含ROS2 Humble和CUDA配置)

本文提供了一份详细的Autoware.universe编译指南,涵盖Ubuntu 22.04系统优化、ROS2 Humble安装避坑、CUDA配置及Demo运行技巧。通过分步操作和实战经验,帮助开发者高效完成环境搭建,避免常见错误,提升自动驾驶开发效率。

weixin_30642561的博客 347

linux 转换文件名编码和文件编码

查看文件编码 在Linux中查看文件编码可以通过以下几种方式: 1.在Vim 中可以直接查看文件编码 :set fileencoding 即可显示文件编码格式。 如果你只是想查看其它编码格式的文件或者想解决用Vim查看文件乱码的问题,那么你可以在 ~/.vimrc 文件中添加以下内容: set encoding=utf-8 fileencodings=ucs-bom,utf...

架构师的成长之路 3032

用了7年的 source insight 3.5 背景色及字体配置(提升code效率)

在此记录并share用了7年的 source insight 3.5 背景色及字体配置,提升阅读代码效率

Chasing Freedom 7526

Express 解决中文乱码

方法,向客户端发送中文内容时,就会出现乱码问题,此时需要手动设置发送内容编码格式。

sudo0m的博客 1235

瑞芯微RK3588与FPGA的PCIe DMA通信性能优化实战

本文深入探讨了瑞芯微RK3588与FPGA之间PCIe DMA通信的性能优化实战。针对高速数据采集、AI推理等场景下的带宽瓶颈,文章从驱动配置、DMA描述符、中断处理、零拷贝技术及系统级调优等多个层面,提供了详细的优化策略与代码示例,旨在充分释放PCIe 3.0的理论带宽潜力,提升数据传输效率与稳定性。

sand8的博客 418

为什么你的SiC MOSFET仿真不准?可能是离子注入的‘沟道效应’在捣鬼(Silvaco BCA模块详解)

本文深入分析了SiC MOSFET仿真中离子注入沟道效应的关键影响,揭示了Silvaco BCA模块在模拟SiC晶向和角度参数时的核心设置要点。通过详细解析晶圆偏切与注入角度的等效关系,提供优化MOSFET沟道区注入仿真的五步实战方法,帮助工程师将阈值电压仿真误差从26%降低到5%以内。

weixin_26789847的博客 410

解压乱码,判断 zip 压缩包编码是 GBK,还是 UTF-8

问题 java 程序解压 zip 类型的压缩包,使用 WinRAR 压缩的解压出来就会乱码。 我使用的是 zip4j 解压的,根本原因还是解压时候编码问题。 如何鉴别文件编码 网络上提供的几种都以失败告终: 1、判断文件首字节 2、使用 cpdetector 鉴别编码失败,怎么办? 有个有趣的现象:如果自己写解压程序的话,编码不对会报异常,而不是乱码了。 因此我们可以使用异常来判断是否可行。 自己写解压 public static void doUnArchiver(File srcfile, String

sqber 1万+

KubeVela入门到精通-K8S多集群交付

KubeVela是一个功能强大、易于使用、高度可扩展的应用交付与管理平台。它基于Kubernetes和OAM 技术构建,通过开放应用模型(OAM)来作为顶层的抽像,提供了声明式部署、多集群/混合环境支 持、插件与扩展性、中心化管控以及易于使用与可观测性等特点。

小杨同学的博客 1269

【字符集三】系统字符集、文件字符集、vs工程字符集

这里写目录标题一、系统字符集1、Windows2、Linux二级目录三级目录 一、系统字符集 1、Windows 方法1 方法2 2、Linux 二级目录 三级目录

junxuezheng的博客 5128

《点云进阶》专栏文章目录

点云进阶》专栏文章目录

点云侠的博客 4905

102、栅极驱动芯片选型与设计

文章摘要 本文分享了栅极驱动芯片选型与设计的实战经验。通过一次因驱动芯片选型不当导致的炸管事故,作者总结了栅极驱动芯片选型的五个关键参数:峰值驱动电流、驱动电压范围、传播延迟匹配、欠压锁定和隔离等级。文章详细分析了自举电路设计中的常见陷阱,以及栅极电阻对开关特性的影响,并强调了PCB布局布线的重要性。最后,作者提供了七条实用建议,包括避免通用型驱动芯片、关注CMTI参数、使用插件电阻等。核心观点是:栅极驱动设计需要综合考虑参数匹配、电路布局和实际调试,示波器实测波形是验证设计的唯一标准。

2401_88858637的博客 44

linux下查看文件编码和修改文件编码

1、查看当前目录下所有文件编码: 查单个更改 '*' 就可以 [root@cs174 export]# find . -name 'test.csv' | xargs file ./test.csv: UTF-8 Unicode text [root@cs174 export]# find . -name '*' | xargs file .: direct...

chl183的博客 3385

机器学习实战7-基于机器学习算法预测相亲成功率

大家好,我是微学AI,今天给大家介绍一下机器学习实战7-基于机器学习算法预测相亲成功率,随着社会的发展,大家都忙于事业,对自己的终身大事就耽搁了,相亲是一种传统的寻找伴侣的方式,随着时代的发展,相亲的方式也在不断地改变。在这个过程中,了解相亲双方的信息以及预测相亲是否成功变得越来越重要。本文将介绍如何使用随机森林算法对相亲成功进行预测,通过分析男女双方的房子、车子、长相、家庭条件、父母情况、生活习惯、学历、性格、兴趣等因素,来预测相亲是否成功。

微学AI的博客 3035

Linux命令--查看和修改文件的编码格式的方法

原文网址: 简介 查看文件编码格式 方法:使用vim命令。 1.用vim打开文件 vim filename 2.查看编码格式 :set fileencoding 修改文件编码格式 需求:将一个文件转换成UTF-8格式。(原来是GBK格式)。 法1:vim 1.打开文件 vim filename 2.设置编码格式 :set fileencoding=utf-8 法2:iconv iconv -f gbk -t utf8 inputFile.txt -o outputF

IT利刃出鞘的博客 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Linux中查看文件编码和修改文件编码

最近遇到一个需求,给我两个大文件,映射到Hive表中。 文件中每个字段的值都有"",字段分隔符为’,’ ,通过vi查看文件内容正常,没有出现乱码。 首先想到的方法是在hive中创建对应的表,然后通过put,将文件上传到hive表对应的hdfs目录下,然后查询发现乱码。 下面来聊聊具体过程和解决办法: 创建对应的hive表 create table temp.temp_bianma_tb ( c...

fuyun6363的博客 2629

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

linux下文件编码查看及修改

在Windows中默认的文件格式是GBK(gb2312),而Linux一般是UTF-8。查看文件编码  在Linux中查看文件编码可以通过以下几种方式:  1.在Vim中可以直接查看文件编码(测试通过)  :set fileencoding  即可显示文件编码格式。  查看其文件编码格式或者用Vim查看文件乱码的问题,在  ~/.vimrc 文件中添加以下内容:  set encoding=utf

囉哩八唆 2984

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

上一篇: linux下iconv()函数的用法
下一篇: E: Sub-process /usr/bin/dpkg returned an error code (1) 出错解决方案
Zwarwolf
博客等级 码龄20年 693粉丝 123原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值