Operation and Maintenance
Linux Operation and Maintenance
Garbled characters appear when running files written in Windows on Linux
Garbled characters appear when running files written in Windows on Linux

Question:
Copy the code (.m) file written in matlab under Windows to Linux (Ubuntu), and the comments are in Chinese It's all gibberish, and vice versa, it's the same problem.
Reason:
The default encoding used under Windows is GB2312, and the default used under Linux is UTF-8. Therefore, the code generated under Windows is GB2312 encoding, which is of course recognized as garbled code under Linux; conversely, the code is garbled in the same way.
Free video tutorial recommendation: linux video tutorial
Solution:
Transcode the file encoding format directly.
Use the iconv command under linux to change the encoding of the file:
test1.m is converted from GB2312 to UTF-8 (the code of matlab under windows runs under linux)
iconv -f GB2312 -t UTF-8 test1.m -o test1.m
test2.m is converted from UTF-8 to GB2312 (the code of matlab under Linux runs under windows)
iconv -f UTF-8 -t GB2312 test2.m -o test2.m
If there are too many files and batch processing is required, the shell written as follows can be used Script batch conversion encoding.
Usage: Place the script in the folder that needs to be converted, and execute the script to convert all files in the current directory and its subdirectories into the specified encoding method.
The execution is as follows:
Convert from GB2312 to UTF-8
./convertMatlab.sh win
Convert from UTF-8 to GB2312
./convertMatlab.sh linux
Tips: Ordinary users do not have execution permissions , you need to use chmod x convertMatlab.sh to increase execution permissions
Recommended related articles and tutorials: linux tutorial
The above is the detailed content of Garbled characters appear when running files written in Windows on Linux. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Fresh Guide: Fix Windows Printer Problems and Spooler Issues
Aug 29, 2025 am 08:12 AM
IfyourWindowsprinterisn'tworking,trythesesteps:1.RestartthePrintSpoolerservice.2.Runthebuilt-inPrinterTroubleshooter.3.Reinstalltheprinterdriver.4.Manuallyclearstuckprintjobs.5.UseCommandPrompttoresetprintingcomponents.
What is a pass key? How to create it? OEE Exchange's pass key tutorial ((APP/Web)
Aug 29, 2025 pm 03:54 PM
What is Pass Key Pass Key is a new type of authentication technology that allows users to access their accounts without manually entering their password when logging into a website or application. Through the pass key, users can complete identity authentication using fingerprint recognition, facial scanning or device unlocking methods (such as PIN code). This technology is based on the encryption key pair mechanism, providing efficient and secure protection capabilities, and effectively resisting cyber threats such as phishing attacks. Advantages of Pass Key 1. Password-free login, which is more convenient to operate: use fingerprints, faces and other biometric methods to log in directly to the account, so as to save the hassle of repeatedly entering passwords and avoid login failures caused by entering the wrong password. 2. Stronger security: Pass keys follow technical standards formulated by the FIDO Alliance and W3C, and use asymmetric encryption algorithms to replace traditional secrets.
How to turn off advertising ID in Windows
Aug 27, 2025 am 06:03 AM
OpenSettingsviatheStartmenu,thengotoPrivacy&security(orPrivacyonWindows10).2.ClickGeneralintheleftmenuandlocatetheadvertisingIDoption.3.Toggleoff"LetappsuseadvertisingIDtomakeadsmoreinterestingtoyoubasedonyourappactivity"todisableit.Dis
'Windows can't find one of the files in this theme' [Fixed]
Aug 28, 2025 am 06:44 AM
First, confirm whether the theme file is complete. 1. Enter the corresponding theme folder of C:\Users\YourName\AppData\Local\Microsoft\Windows\Themes\; 2. Check whether the .theme file exists; 3. Confirm whether the referenced picture is in the Backgrounds subfolder; 4. Verify whether the referenced .msstyles file actually exists; if any file is missing, you need to download the theme package and install it correctly to solve the problem.
How to find the classic Control Panel items in Windows
Aug 26, 2025 am 07:12 AM
TheclassicControlPanelinWindows10and11canbeaccessedviaStartmenusearch,Runcommand(control),FileExplorer,orright-clickingtheStartbutton.2.ControlPaneloffersthreeviews:Category,Largeicons,andSmallicons,withiconviewsbeingfastestforlocatingspecifictools.3
How to use virtual private networks (VPN) on Windows
Aug 26, 2025 am 07:20 AM
TosetupanduseaVPNonWindows,firstopenSettings>Network&Internet>VPNandclickAddaVPNconnection;1.SetVPNprovidertoWindows(built-in);2.Enterarecognizableconnectionname;3.Inputtheservernameoraddressprovided;4.SelectthecorrectVPNtype(e.g.,IKEv2,L2T
Fixed: Windows Is Showing 'Windows could not automatically detect this network's proxy settings'
Aug 29, 2025 am 04:23 AM
DisableAutomaticProxyDetection(IfNotNeeded):Ifyou'reonahomeorsmallofficenetwork,disableautomaticproxydetectiontoresolvetheerror;pressWindows I→Network&Internet→Proxy,toggleAutomaticallydetectsettingstoOff,andensureUsesetupscriptisoffunlessaPACfil
How to Fix Windows 'We couldn't create a new partition or locate an existing one' Error
Aug 29, 2025 am 09:03 AM
Ifyougetthe"couldn'tcreateanewpartition"errorduringWindowsinstallation,trythesesteps:1.UseDiskParttocleanandrepartitionthedrive.2.CheckBIOSSATAmode(switchbetweenIDE/AHCI).3.Loadproperstoragedriversduringsetup.4.ConvertdiskbetweenMBRandGPTto


