- Conversion of files from Windows to Unix format
- Notes:
- dos2unix and unix2dos
- NEWS CONTENTS
- Old News 😉
- Ubuntu Genius’s Blog
- HowTo UNIX — Linux Convert DOS Newlines CR-LF to Unix-Linux Format
- Conversion from DOS to UNIX
- How to Make the Switch From Windows to Linux
- Choose Your Distribution
- Create Your Installation Drive
- Install Linux on Your PC
- Get Acquainted With Linux and Install Some Apps
- How to Install and Uninstall Apps
- How to Update Apps
Conversion of files from Windows to Unix format
Note: The following information is provided in part by the Extreme Science and Engineering Discovery Environment ( XSEDE ), a National Science Foundation (NSF) project that provides researchers with advanced digital resources and services that facilitate scientific discovery. For more, see the XSEDE web site.
The format of Windows and Unix text files differs. In Windows, lines end with both the line feed and carriage return ASCII characters, but Unix uses only a line feed.
There are several utility software to convert text files from UNIX or Linux to DOS operating systems and vice-versa; however, it always helps to know the manual conversion. In shell programming languages like UNIX or Linux the text files conclude with a new line operator»\n» also known as the line feed and its ASCII code is 0A. A DOS Text file concludes a line by the carriage return or the entry key «\r»: its ASCII code is 0D. The lines in the DOS end with CRLF or with «\r\n». To convert DOS text into UNIX or Linux erase the «\r»; you can also use ASCII codes if you are using GNU-sed version.
As a consequence, some Windows applications will not show the line breaks in Unix-format files. Likewise, Unix programs may display the carriage returns in Windows text files with Ctrl-m ( ^M ) characters at the end of each line.
Notes:
- Sometimes when you edit files in Windows and Unix you get a file that have fragments in «Unix style» and fragments in Windows style. dos2unix does not convert such files. Sometime there are even fragments that have only ^M at the end. See How do I convert between Unix an
In this case you can use multiple Perl one liners along the following lines
For simple conversion you can use FTP, screen capture, unix2dos and dos2unix, tr , awk, Perl, and vi to do the conversion. You can also use CYGWIN.
When using an FTP program to move a text file between Unix and Windows, be sure the file is transferred in ASCII format, so the document is transformed into a text format appropriate for the host. Some FTP programs, especially graphical applications (e.g., Hummingbird FTP), do this automatically. If you are using command line FTP, before you begin the transfer, enter:
Note: You need to use a client that supports secure FTP to transfer files to and from Indiana University’s central systems. For more, see At IU, what SSH/SFTP clients are supported and where can I get them?
dos2unix and unix2dos
The utilities dos2unix and unix2dos are available for converting files from the Unix command line.
To convert a Windows file to a Unix file, enter:
To convert a Unix file to Windows, enter:
You can use tr to remove all carriage returns and Ctrl-z ( ^Z ) characters from a Windows file:
However, you cannot use tr to convert a document from Unix format to Windows.
To use awk to convert a Windows file to Unix, enter:
To convert a Unix file to Windows, enter:
Older versions of awk do not include the sub function. In such cases, use the same command, but replace awk with gawk or nawk .
To convert a Windows text file to a Unix text file using Perl, enter:
To convert from a Unix text file to a Windows text file, enter:
You must use single quotation marks in either command line. This prevents your shell from trying to evaluate anything inside.
In vi, you can remove carriage return ( ^M ) characters with the following command:
Note: To input the ^M character, press Ctrl-v , and then press Enter or return .
In vim, use :set ff=unix to convert to Unix; use :set ff=dos to convert to Windows.
This document was developed with support from National Science Foundation (NSF) grant OCI-1053575. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.
Top updates Your browser does not support iframes. | ||||
Bulletin | Latest | Past week | Past month | Google Search |
NEWS CONTENTS
- 200218 : Ubuntu Genius’s Blog ( October 26, 2010 , Ubuntu Genius )
- 200218 : HowTo UNIX — Linux Convert DOS Newlines CR-LF to Unix-Linux Format ( HowTo UNIX — Linux Convert DOS Newlines CR-LF to Unix-Linux Format, )
Old News 😉
Ubuntu Genius’s Blog
October 26, 2010 | Ubuntu Genius
Most people don’t realise that when they hit the Enter key to create a new paragraph in a text file, something very different is going on behind the scenes in the three major operating systems: Windows, Macintosh and Linux. The «end-of-line delimiter» (often expressed as «End-Of-Line«, «End of Line«, or just «EOL«) – which some of you know as the «line break» or «newline» – is a special character used to designate the end of a line within a text file.
UNIX-based operating systems (like all Linux distros and BSD derivatives) use the line feed character (\n or ), «classic» Mac OS uses a carriage return (\r or ), while DOS/Windows uses a carriage return followed by a line feed (\r\n or ). Now that Mac OS X is based on FreeBSD‘s file system, it follows the UNIX convention.
Now, the reason most people don’t know about all this is because nobody really should have to. But while users of Linux distros and Mac OS can open Windows text files in basically any available editor and not even know the difference, the same can’t be said for Windows users opening files created in one of the other operating systems.
If you type up a simple text file in Ubuntu and save it in the default «Unix/Linux» format, in Windows it will appear as one continuous paragraph, with black squares where the line breaks (or new paragraphs) should be. While you can open the file in a more advanced text editor (or proper word processor) to view it as it should look, others you’ve sent it to are just likely to double-click it and let it open in Notepad (which can only handle MS-DOS EOL).
Occasionally, the reverse is the issue, but you can convert Windows text files to UNIX easily with Gedit, as well as convert them via the terminal, so hopefully the following guide will be of use.
For more detailed info on End-Of-Line, go to the Wikipedia page.
Converting Windows EOL to Linux via the Terminal
If you find the text editor you’re using to display Windows files in Ubuntu shows ^M instead of a line break (not very likely with even the most lightweight text editors, but something you’ll probably come across if you display the text in a terminal), don’t worry – just convert them to Unix/Linux format.
While you can actually open them in Gedit and use Save As… to save over them (or to create copies) in the correct format, for more than a couple of files this would be the long, complicated solution.
By far the quickest and easiest approach is to convert the offending files via the command-line. This way, you could batch-convert hundreds of such files at once, not have to do them individually.
There are actually quite a few ways to do this, but we’ll look at a couple of tiny packages you can install, and the related commands to use.
The first – the tofrodos package – is undoubtedly the most widely-used, so we’ll look at that in detail – especially since many of the guides out there are outdated, since the commands it contains have been renamed.
The second is a little package called flip, and since it’s tiny and won’t cause any issues, it’s worth installing as a backup (just in case. I found it useful after trying to get tofrodos going on a new system, before I found out the commands were changed).
There is no actual command tofrodos, as it is just the package that contains the commands todos and fromdos. Currently, the vast majority of online guides will list the commands as unix2dos and dos2unix, but as the developer states:
With this release the symlinks «unix2dos» and «dos2unix» are dropped from the package. This will allow the introduction of the original dos2unix package, which also supports conversion to MacOS style files.
So now you can choose to use either todos (to convert to Windows) and fromdos (to convert to Linux), or just fromdos with options (fromdos -u to convert to DOS, and fromdos -d to convert to UNIX, though obviously the -d option really isn’t needed, as it is the default behaviour for the fromdos command).
We’ll use fromdos, as it is easier to remember, and show how to alter a single file, or all text files in a given folder. When you’re ready to proceed, open a terminal in the folder containing the text file(s) and use one of the following commands (note that for the purpose of illustration, the .txt suffix is used, but you can specify any other extension for your text files).
To Convert to UNIX/Linux via Terminal:
Single file (remember to replace filename.txt with the actual name of the file)
fromdos filename.txt
All text files in a folder (if the extension differs to .txt, simply replace it in the command)
fromdos *.txt
Similarly, flip is easy to use:
flip -u filename.txt (or flip -u *.txt for multiple files)
HowTo UNIX — Linux Convert DOS Newlines CR-LF to Unix-Linux Format
Task: Convert Dos TO Unix Using tr Command
Type the following command:
Task: Convert Dos TO Unix Using Perl One Liner
Type the following command:
Task: Convert UNIX to DOS format using sed command
Type the following command:
Task: Convert DOS newlines (CR/LF) to Unix format using sed command
If you are using BASH shell type the following command (press Ctrl-V then Ctrl-M to get pattern or special symbol)
Note: sed version may not work under different UNIX/Linux variant, refer your local sed man page for more info.
The text files under Unix end their line with the symbol «\n» (called Line Feed and noted LF, ASCII code = 0A).
Text files under DOS by a «line», end their line with the symbol «\r»(called Carriage Return and noted CR, ASCII 0D).
Thus, every line in a DOS file ends with a CRLF sequence, or \r\n.
Conversion from DOS to UNIX
With the GNU-sed(gsed 3.02.80) version, we can use the ASCII notation:
Conversion from UNIX to DOS
Just do the opposite of the previous command, namely (the «^M» being entered in the same way (CTRL-V + CTRL-M)): Note:
With the GNU-sed(gsed 3.02.80) version, we can use the symbolic notation «\r»:
Источник
How to Make the Switch From Windows to Linux
If you’re sick of Windows 10 or don’t want to upgrade to Windows 11, you can install Linux instead. Here’s how to make the switch to an open-source operating system and install apps.
Microsoft is getting closer to replacing Windows 10 with the sleeker Windows 11, but if you’re sick of embedded advertisements, constant updates, data collection, software lock-ins, and rising hardware requirements, we don’t blame you. The good news is you have options.
If you’ve been thinking about making the jump to a different operating system, now is the perfect time. But you aren’t stuck with the Windows-macOS binary, and don’t have to settle for the browser-based Chrome OS. Instead, you can turn to the world of Linux.
Choose Your Distribution
Unlike Windows and macOS, there isn’t just one version of Linux. Instead, Linux is packaged into many different distributions, or «distros,» each with their own interface and set of features. One may use a Mac-like interface with a dock and an «app store,» while others may use a more minimalist interface and require installing apps from the command line.
Exploring the bevy of Linux distributions out there is a fun part of the hobby, but for your first installation, you will likely want something popular and beginner-friendly, so it’s easy to get help when you need it. That’s why I recommend starting with Linux Mint.
There are a lot of distributions that aim to mimic Windows in layout and functionality, like Zorin OS, but they’re on the smaller side, and you won’t have as big a community to tap as you learn your way around. Ubuntu, on the other hand, is arguably the most popular distro on desktop PCs, but it isn’t very Windows-like at all these days.
Linux Mint is a perfect in-between option: it’s designed for beginners, offers a familiar desktop environment, and it’s based on Ubuntu, so you can make use of the enormous Ubuntu/Mint community when you need help.
You’re free to check out other distros instead, but I’ll be using Mint for the purposes of this guide, and I recommend you do too. It’s not my personal distro of choice, but it’s great for new Windows migrants, and it’s easier to explore other distros once you’ve nailed down the basics on a beginner-friendly system.
Create Your Installation Drive
Head to Mint’s download page and choose the 64-bit «Cinnamon» version. Cinnamon is the desktop environment I recommend for former Windows users, though MATE is also pretty Windows-like, even though it’s a bit less modern. XFCE is ideal for old or low-powered PCs, thanks to its light resource usage. Mint’s download page provides a number of links depending on where you live. If you use BitTorrent, I recommend grabbing the torrent file, which will download much faster.
The installer will come as an ISO, or disc image file. To install it on your system, you’ll need to burn the file to a DVD or USB flash drive. We’re going to do the latter using a tool called Rufus. Install Rufus, open it up, and insert a flash drive that’s 2GB or larger. (If you have a fast USB 3.0 or 3.1 drive, all the better.) You should see it appear in the Device drop-down at the top of Rufus’ main window.
Next, click the Select button next to Disk or ISO image, and choose the Linux Mint ISO you just downloaded. Press the Start button, and if prompted to download new versions of Syslinux, click Yes. Note that this will erase your flash drive, so make sure there isn’t anything important on there before continuing. When it’s finished, you’ll see a success message and your flash drive will be named LINUX MINT.
Now it’s time to back up your data and reboot your computer. Buckle your seat belts because it’s time to install Linux.
Install Linux on Your PC
As your computer reboots, you should see a message telling you to press a certain key to access the Boot Menu (usually something like F12). If not, you’ll see a key to enter Setup (often Delete). Press one of those keys, and look for the option to boot from the inserted USB drive. (If you enter the full setup menu, it’ll be in a Boot settings menu somewhere, and you’ll have to exit the menu to reboot again when you’re done.)
You will then be greeted by GRUB, Linux Mint’s boot menu, where you can choose to boot into Linux Mint. If you run into any errors, you may need to Google around for a fix. I had to enable the nomodeset option for my graphics card, for example. Others may have to tweak or disable Secure Boot in the BIOS.
This installer is what we call a Live CD, where you can actually poke around and use the Linux Mint desktop before installing it. This will give you a chance to see if this particular distro appeals to you without it actually touching your system drive. Once you’re satisfied, double-click the Install Linux Mint icon and go through the wizard.
Be sure to check the box next to Install third-party software, since it contains useful drivers and codecs you almost certainly want. From here, you can wipe your hard drive entirely, erasing all traces of Windows and using Linux as your only operating system. (Make double sure you’ve backed up your data before doing this.)
Alternatively, you can divide your drive up into two partitions and dual boot Linux alongside Windows. This will allow you to reboot into one or the other whenever you want. If nothing else, it’s comforting to know you have that safety net during the transition before you remove Windows entirely.
Choose the relevant option from the Installation Type menu, and click Install Now. The process may take a little while, but when it’s done, you’ll get a success message. Click the Restart Now button to boot into Linux Mint and start getting acquainted with your new OS.
Get Acquainted With Linux and Install Some Apps
When you reboot, you’ll be dropped into the Linux Mint desktop once again—only this time, it’s installed on your PC. The basics are pretty familiar: click the button in the lower-left corner to see applications, manage windows from the bottom taskbar, and so on. There are, however, a few things in Linux that work differently than in Windows, with apps being the biggest.
In Linux, it’s less common to download apps from the web. Instead, each distro has its own repository—kind of like a free app store, with a directory of popular apps. You can install an app from the repositories in one of two ways: from a graphical software manager (again, which looks like an app store) or from the command line.
To open Linux Mint’s Software Manager, click the menu button in the lower-left corner and head to Administration > Software Manager (or just start typing «software manager,» like you would in Windows). From here, you can download plenty of free, open-source apps.
Some are Linux versions of their Windows counterparts, like Steam and Spotify, while others are open-source alternatives to common apps (Banshee is a music player similar to iTunes, Gimp is an image editor akin to Photoshop). You can browse here or search for apps using the bar at the top.
How to Install and Uninstall Apps
If you know what you’re looking for, it’s generally faster to install apps from the command line. And while it may seem intimidating at first, Linux relies on the command line for various tasks, so it might behoove you to get comfortable with it. To install an app—let’s say the open-source media player VLC—open a Terminal window and run:
Sudo apt update
sudo apt install vlc
Let’s break that down: «sudo» tells the system to run the command as root (or, as it might be called in Windows, as an administrator), «apt» is the name of Linux Mint’s package manager, and «update» ensures the list of available apps is up to date.
The second command, which includes «install vlc,» is self-explanatory. You should run «sudo apt update» before installing any app, and you can replace «vlc» with the name of any app you want to install. If you aren’t sure what the repository calls it, you can run:
sudo apt cache search vlc
To uninstall an app, just run:
sudo apt remove vlc
This will remove the app, but not your configuration files, so if you decide to reinstall it later, your settings will still be there.
If you want to remove configuration files too, you can instead run:
sudo apt purge vlc
How to Update Apps
You’ll also want to periodically update those apps, so you have the latest versions. You can do this, again, in two ways: from the graphical tool or from the command line.
For the graphical tool, click the shield icon in the lower-right corner to open the Update Manager app. You can then click the Install Updates button to update all your software.
Alternatively, you can open a Terminal and run two commands:
sudo apt update
sudo apt upgrade
Again, the «update» command checks for new versions of your software, and the «upgrade» command actually upgrades all your apps. You’ll want to run these two together, just like you do for installing new apps.
Those are the most crucial things to know right now, but take some time to browse around Mint’s interface and its settings to see what it has to offer. The Welcome window that appears at startup can be a big help—its First Steps area will show you how to choose different desktop layouts, install multimedia codecs you might want, and install necessary drivers for your hardware.
You’ll get the hang of the basics pretty quickly, but the Mint and Ubuntu forums are always there to help if you get stuck. Just be sure to search around, since there’s a good chance someone before you has had the same question.
Like What You’re Reading?
Sign up for Tips & Tricks newsletter for expert advice to get the most out of your technology.
This newsletter may contain advertising, deals, or affiliate links. Subscribing to a newsletter indicates your consent to our Terms of Use and Privacy Policy. You may unsubscribe from the newsletters at any time.
Your subscription has been confirmed. Keep an eye on your inbox!
Источник