UNIX/Linux

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.control-Ms
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

Leave a comment

 

Changing your CVS host

February 5th, 2009

What do you do if the host name of your CVS server changes? For example, here’s my case. I checked out a whole lot of CVS modules from the repository while my laptop was on the domain. Now however, thanks to Vista SP1 not playing with an antiquated NT domain, the laptop can’t join the domain so to connect to a server I need to qualify its name with a domain. So, whereas I checked out the modules using the hostname “cvshost”, I now need to use “cvshost.mydomain.co.uk”.

Unfortunately, TortoiseCVS has no way to change the host names for modules you’ve already checked out. WinCVS can, supposedly, do this thanks to a macro. However, WinCVS stubbornly tells me I don’t have Python installed (I do) and therefore won’t let me use macros.

The solution is to just go through all the CVS “Root” files and change the host name. The Root file lives in the CVS directory at each level within a checked out module. This would be a laborious task by hand, but if you have SUA (Microsoft’s Subsystem for UNIX Applications) and Perl installed it’s easy. Just pull up a Korn shell and browse to the directory within which your checked out CVS modules live.

Run the following command.

find . -name 'Root' -print0 | xargs -0 perl -pi -e 's/oldhostname/newhostname/g'

For example, I ran the command:

find . -name 'Root' -print0 | xargs -0 perl -pi -e 's/cvshost/cvshost.mydomain.co.uk/g'

Which changed the Contents of the Root file from:

:pserver:achristie@cvshost:/company/repository

to:

:pserver:achristie@cvshost.mydomain.co.uk:/company/repository

Leave a comment



Adding ^M characters in vi

November 25th, 2008

This is an obscure one. There are lots of Web pages out there to tell you how to get rid of ^M characters in text files (dos2unix is your friend) but occasionally you need to edit a settings file on UNIX server where the file is normally edited using a Windows client. If you don't add the ^M character at the end of each line, the lines will run together next time the file is viewed in Windows.

To add a ^M in vi enter Ctrl+V followed by Ctrl+M.

Leave a comment



Deleting a symbolic link via FTP

October 14th, 2008    1 Comment

I just struggled for a while to delete a symbolic link on my Web server that was causing me problems. The main problem was that I couldn't download it, which meant that I couldn't download the whole of my WordPress installation as a backup. I had to copy directories down piecemeal to specifically avoid copying that file (advanced-cache.php).

I'm not sure what the problem was because the file the symlink was pointing to (wp-content/plugins/wp-cache/wp-cache-phase1.php) was still there. I had to use ClassicFTP to find this out because FileZilla doesn't show you were a symlink is pointing to. In fact, FileZilla treats symlinks as if they are directories and doesn't show the destination. ClassicFTP does, but doesn't show the ownership or permissions on files, which makes it inferior to FileZilla.

The other problem was that I couldn't simply delete it in FileZilla or ClassicFTP.

The solution I finally found was just to FTP to my Web server from the good old Windows command line. Fire up a command console window, type: ftp <host> then, when prompted, your user name and password. Use ls and cd to navigate to the directory containing the symlink.

Strangely, the symlink doesn't show up when you do an ls. However, if you do delete <symlink name> it will delete the symbolic link successfully.

Job done!

Potentially similar posts

Leave a comment



Ubuntu on Virtual PC

September 12th, 2008    3 Comments

I'm quite happy using Windows and don't see much appeal in Linux. I have not-so-fond memories of wasting lots of my free time in the past installing and configuring Linux. That was back in the days before graphical Linux installers, when getting a Linux distro to a usable state was a fiendishly complicated ordeal. So I don't have any particular love for Linux as an operating system.

However, it's occasionally useful to have a Linux machine available to test something out, and great way to do this is to use a virtual machine. VMware would be your first choice if you want a virtual Linux machine, but, with a little effort, you can also use Microsoft Virtual PC.

Here's how to get Ubuntu on Virtual PC:

  1. Download and install Virtual PC.
     
  2. Download an Ubuntu Desktop Edition ISO. I downloaded 8.04 ("Hardy Heron").
      
  3. Start Virtual PC, and create a new machine.

    (Video by Robert Cain: http://arcanecode.wordpress.com/)
      
    Note: Make sure to pick “Other” as the OS type.
    Give the machine 512 MB of RAM.
      
  4. Start the new virtual machine.
      
  5. When it starts up, go to the CD menu and choose Capture ISO image, pointing it at the desktop ISO you downloaded from Ubuntu. Capturing an image means the ISO file will show up like a CD in the virtual machine.
      
  6. Ubuntu will start running from the CD image. When it starts, choose your language and then, at the next screen, press F4 to select an alternate starting mode.
    ubuntu-install
      
  7. When the menu pops up, change to Safe graphics mode and press Enter.
    There is a problem with the mouse not working in Virtual PC and this takes a little fiddling about to fix it. There is also an issue with sound (see the link at the bottom of this post for details about how to fix that - personally I didn't need sound, so I didn't bother trying to fix that).
      
  8. Press F6.
     
  9. Edit the command that is displayed, using the arrow keys to move the cursor to the end of the line and adding a space followed by “noreplace-paravirt” (without the quote marks) to the end of the command, then press Enter.
      
  10. Leave the selected option as Try Ubuntu without any change to your computer.
    Note: do not choose the Install Ubuntu option.
      
  11. After Ubuntu loads (note that at this point it's just running from the CD image, it's not installed on the virtual machine) double-click Install on the desktop.
    This runs the Ubuntu installer.
      
  12. Follow through the installer. This part is very simple.
       
  13. Once the install is done, go back into the CD menu (right-hand Alt key gets the mouse pointer out of the virtual machine) and release the ISO, otherwise when you reboot you'll go back to the installation menu.
      
  14. Click the red button, top right of the Ubuntu desktop and shutdown the virtual machine.
    If it hangs at this point, don't worry about it.
      
  15. Close the Virtual PC window and choose to shut down the machine.
     
  16. Go into the Settings for the virtual machine.
    Robert Cain's video shows how to edit the Settings if you've never done this before:

     
  17. Make sure Networking is set to the network adaptor that your PC is currently using.
    Note: if you want to be able to connect to/from the Ubuntu VM and your host PC, you need to use the Microsoft Loopback Adaptor. If this doesn't show up in the list of network adaptors you'll have to install it first. This is really easy. See http://support.microsoft.com/kb/839013, or this video from http://veedee-eyes.com

      
  18. Save the Settings.
      
  19. Start up the virtual machine again.
      
  20. Once it gets to the "GRUB" line, press Esc.
    You should now see 3 entries to select from.
      
  21. Leave Ubuntu 8.04, kernel 2.6.24-16-generic selected and press e.
      
  22. On the next page, select the second entry that reads kernel /boot/vmlinuz… and press e again.
       
  23. You will see a command line that ends with “xforcevesa”. Edit this, as before, adding a space followed by “noreplace-paravirt” (without the quotes) at the end of this line, then press Enter.
       
    You are now back at the previous selection screen with the entry kernel /boot/vmlinuz… still selected.
      
  24. Press b and Ubuntu should boot correctly.
      
  25. Once Ubuntu has loaded, open a terminal window (Applications > Accessories > Terminal) and on the command line enter:
       
    sudu nano /boot/grub/menu.lst
     
  26. Enter your password and page down to near the bottom and locate “kernel /boot/vmlinuz…" in the “Ubuntu 8.04, kernel 2.6.24-16-generic” section.
      
  27. Move the cursor to the end of the line after xforcevesa and add a space followed by “noreplace-paravirt” (no quotes).
      
  28. Ctrl + O to write out.
      
  29. Enter to accept the name.
     
  30. Ctrl + X to close the file.
      
    Ubuntu should now be running inside Virtual PC.
      
  31. Click the network icon in the upper right side of the Ubuntu toolbar:
    ubuntu-network 
      
  32. Choose Wired Network.

That's it.

Now you can fire up an Ubuntu machine whenever you need it. And when you close it down, choose Save State and when you start it up again you'll be able to pick up exactly where you left off - for example, any programs that were running when you saved state will still be running when you start up the VM again in six months time.

I found the following site extremely helpful:

http://arcanecode.wordpress.com/2008/04/24/installing-ubuntu-804-under-microsoft-virtual-pc-2007/

If you get stuck, it's worth reading through all the comments on this page, which provide a lot of useful information.

Leave a comment



^ back to top ^

Page 1 of 912345»OlderLast »