Control-Ms and zipping in UNIX
August 14th, 2009
This is one of those “So’s I Remember For Next Time” posts. A couple of obscure UNIX how-tos.
Tip 1 – Entering Control-Ms in vi
When you’re editing a text file in vi and the file was created in a Windows editor, you’ll see control-M (^M) characters at the end of each line.
If you want to add a new line and you want it to show up as a separate line in Windows, you’re going to have to add a control-M at the end of the line. The ^M is a single character, so you can’t just type ^ and then type M. You might think, given the name of the character, you could just hold down the Ctrl key and press m, but it’s not quite that simple.
What you need to do, in vi, is press Ctrl+v followed by Ctrl+m.
Tip 2 – Zipping files in UNIX
Usually when I’m working in UNIX and I want to compress a file, I use gzip:
gzip filename
This replaces the named file with a compressed version of it, with .gz added onto the end of the file name. To unzip the file do:
gunzip filename
This replaces the .gz file with the original file.
However, sometimes you need to create a .zip file. To do this use the zip command, but you need to know the syntax:
zip –r outputfile inputfile
For example:
zip –r temp.zip temp.txt
In fact you don’t need to specify the .zip file extension. If you give a file name without a file name extension, the .zip extension gets added automatically.
A new zip file is created and the original file is not deleted. To unzip just do:
unzip zipfile
This creates a new, unzipped file but does not delete the zip file.
I just tried this out and the following stats for compressing a small text file suggest that gzip is the more effective compression program:
temp.txt 677K
temp.txt.gz 416K
temp.zip 504K
Potentially similar posts
- Restoring Vista’s missing “Text Document” shortcut – April 2009
- New article: taking control of the iPlayer – November 2008
- Adding ^M characters in vi – November 2008
- ITauthor podcast #16 – Flare and Chrome, the pubcast – September 2008
- Some handy Explorer shortcuts – August 2008