Posts Tagged ‘Linux’

uTorrent: How to Share Between Ubuntu and Windows

27/01/2009

While Ubuntu (Wine) and Windows can both run uTorrent, it’s not that easy to keep one copy. Say, for example, that you want to use uTorrent on a Flash drive (USB stick). You run with the problem of having a Z: drive in Wine, which most likely won’t be anything like the structure in Windows (even if you simulate or change the drive letter.)

For example, I have set a partition under a folder in Ubuntu, so the torrent destination path in Wine is Z:\partition\Torrents

In Windows, I can only point a drive letter to a folder, but not the other way around!

I wondered if Windows had anything similar to symbolic links. I figured I could point a drive letter to a folder, then put a symbolic link to the folder, to simulate the path in Wine.

Apparently, it’s not well-known, but there are symbolic links in Windows. They’re not documented, and you need to buy a Microsoft software kit, which includes special tool to create them. They’re also called something else: junction points.

Fortunately, there’s a freeware GUI program that can do this for you: Junction Link Magic. It’s a very small download!

Create a virtual drive

subst Z: C:\vdrive

The vdrive folder is a placeholder, we’ll never actually see vdrive. Create a folder called partition inside Z: (C:\vdrive\partition).

Use Junction Link Magic

Create a link from Z:\partition to the actual partition drive.

When you browse Z:\partition, you should see your Torrents folder.

Now, you can safely run uTorrent from the USB stick, and it won’t notice a thing!

Advertisements

Ubuntu: Show Directory Names in Bash

26/12/2008

This is a very short tip.

I made a small shell script to delete and create a link to my localhost htdocs directory. That way, I never have to move my projects around, I just keep them in separate directories under one main directory.

The problem comes when I forget important things: such as directory names. Instead of just typing ls /projects, I want the script to tell me the options I have.

And so, this little code is born, by not giving the script any arguments:

#!/bin/bash
	if [ -z $1 ]
	then
		echo "No valid user was provided!"
		echo "Possible users:"
		declare -a FOO
		let count=0
		let count2=0
		for d in $( find /projects -maxdepth 1 -type d -printf "%f " ); do
			if [ $count2 -gt 0 ]
			then
				FOO[$count]=$d
			fi
			((count++))
			((count2++))
		done
		echo ${FOO[@]}
	fi

Note: I did it this way because otherwise you get “projects” in the list of results.

Ubuntu: Get VisualBoyAdvance fully working with Wine

10/12/2008

If you miss VisualBoyAdvance’s cheats systems (GameShark, CodeBreaker/ActionReplay, and the memory editor) and you really don’t want to use Linux-based ports because they lack this feature, you’re in luck!

Let’s see the versions:

Wine (development version): 1.1.10
VisualBoyAdvance: 1.8.0-beta3 (more…)

Ubuntu: Your Custom Command PHP Script

31/10/2008

While it’s obvious for experienced users, I’m sure many newcomers to Linux might be wondering how to have a command like chmod, mv, ls, etc.

In other words, a command that accepts parameters, switches, and does interesting things in a language we all love and understand.

First of all, we’ll try phpLipsum, my newest CLI script. I wanted to have a way to access lipsum.com without any fancy GUI, just a quick command.

At YubNub.org they have online commands (very useful!), this command was the one I needed on my computer.

Handling the switches should be easy enough. We’ve seen this before, in previous articles. ;-)

$data = @file_get_contents($url) or die("\nError: Could not download the data.\n\n");
$xml = simplexml_load_string($data);

Once we have our URL built, we can make SimpleXML parse the XML for us. The text will be available through $xml->lipsum.

echo $xml->lipsum;

To make it a little bit easier on the eye I did this:

echo "\n    ".wordwrap(str_replace(".\n", ".\n    ", $xml->lipsum), 80)."\n\n";

This way, the text will be formatted nicely on the CLI. And the spaces shouldn’t affect its appearance on HTML!

Once our script is done, we make it executable. Remember how?

chmod +x lipsum.php

But I wanted to use it like this:

lipsum -a 2

So, we move it to /usr/bin/

sudo cp lipsum.php /usr/bin/lipsum

Note: You can move it (mv) or copy it (cp). I chose to copy it, so that I can keep a backup.

Now, we can finally have our own “command”! It’s quite easy and practical, and we haven’t abandoned our dear PHP. <3

Download phpLipsum

Ubuntu: OpenOffice.org 3.0 DEB archive

13/10/2008

OpenOffice.org is a powerful free open source alternative to Microsoft Office. As the newest version came out today, the OpenOffice.org site was so strained they had to shut it down! They only use the front page to show all the downloads, for now. But for a while, some people reported it was completely offline.

Here is a mirror for the Gzip archive with all the Deb packages needed to install OpenOffice.org 3.0. It’s for Debian-based Linux distros, so if you have Ubuntu or Debian, this is what you need.

Note: I would recommend uninstalling the OOo version that comes with Ubuntu, as it might conflict with the new version.

OOo 3.0 asked me if I wanted to start afresh or import settings from OOo 2.x… So maybe you can keep the old version, import the settings by running OOo 3.0 once, then uninstalling OOo 2.x.

Important: If you’re new or not in a rush, you could wait until it’s available in the Ubuntu repositories.

Once you extract the contents of the archive, open the Terminal in the directory where all the Deb packages are, and run the following command:

sudo dpkg -i *.deb

Enjoy!

Ubuntu: OpenOffice.org 3.0 DEB archive

13/10/2008

OpenOffice.org is a powerful free open source alternative to Microsoft Office. As the newest version came out today, the OpenOffice.org site was so strained they had to shut it down! They only use the front page to show all the downloads, for now. But for a while, some people reported it was completely offline.

Here is a mirror for the Gzip archive with all the Deb packages needed to install OpenOffice.org 3.0. It’s for Debian-based Linux distros, so if you have Ubuntu or Debian, this is what you need.

Note: I would recommend uninstalling the OOo version that comes with Ubuntu, as it might conflict with the new version.

OOo 3.0 asked me if I wanted to start afresh or import settings from OOo 2.x… So maybe you can keep the old version, import the settings by running OOo 3.0 once, then uninstalling OOo 2.x.

Important: If you’re new or not in a rush, you could wait until it’s available in the Ubuntu repositories.

Once you extract the contents of the archive, open the Terminal in the directory where all the Deb packages are, and run the following command:

sudo dpkg -i *.deb

Enjoy!

Ubuntu: Piping and PHP

06/10/2008

On the Piping and File Manipulation post, I talked about directly copying the files elsewhere.

But, what if I wanted to rename and then copy them?

Well, I have yet to research how to strip certain characters from file names with the shell commands, but since I can do PHP, I decided to simply use that knowledge.

Basically, we have our script that takes a file name (with path) and parses it. Then, we can either output the new file names (for another pipe command), or we can use the exec command in PHP!

find . -name "*.mp3" | while read n; do ~/scripts/rename.php "$n"; done

Note: Remember to make the PHP file an executable (chmod +x file.php).

Note 2: The dot represents the current path. You can also replace that with a full path, if you’re not currently in the directory you wish to scan.

To access the file name, you’ll have to use the $argv array. The first index contains the full call (~/scripts/rename.php /path/to/song1.24.a.mp3), the second index contains the file name (/path/to/song1.24.a.mp3). In other words, use $argv[1].

Ubuntu: Piping and PHP

06/10/2008

On the Piping and File Manipulation post, I talked about directly copying the files elsewhere.

But, what if I wanted to rename and then copy them?

Well, I have yet to research how to strip certain characters from file names with the shell commands, but since I can do PHP, I decided to simply use that knowledge.

Basically, we have our script that takes a file name (with path) and parses it. Then, we can either output the new file names (for another pipe command), or we can use the exec command in PHP!

find . -name "*.mp3" | while read n; do ~/scripts/rename.php "$n"; done

Note: Remember to make the PHP file an executable (chmod +x file.php).

Note 2: The dot represents the current path. You can also replace that with a full path, if you’re not currently in the directory you wish to scan.

To access the file name, you’ll have to use the $argv array. The first index contains the full call (~/scripts/rename.php /path/to/song1.24.a.mp3), the second index contains the file name (/path/to/song1.24.a.mp3). In other words, use $argv[1].

Ubuntu: Piping and File Manipulation

06/10/2008

A little case scenario:

I used Rhythmbox to copy some songs to my cell phone’s memory card, and I had a nasty surprise: they all got separated into various directories, and I dislike that.

I didn’t want to manually move each file… So, instead of spending a few minutes doing just that, I spent a couple of hours finding out what piping is and stuff like that.

Most examples are very unrealistic. (“Let’s imagine we have file1, we move it to dir1…”) So I’ll use my particular case as an example.

Okay so I had all my MP3s deep into two directories each: Author / Album / Song

As some of the songs had incorrect or no information, most directories had one or two songs each. It was chaotic to find a song!

Important: If you don’t know what piping is, read this great visual explanation.

We can do this in the Terminal, from the directory that has all our subdirectories/MP3s:

find . -name "*.mp3" | while read n; do cp "$n" /new/path/; done

In the first part, we find all the MP3 files in the current directory (the dot) and its subdirectories. Then, we read its output, line by line. Each line is saved in a variable called n. As each line is, in fact, a file with its complete path, we simply use it as the source argument for the cp command.

Note: I encapsulated “$n” in quotes, otherwise, files with spaces will throw errors.

Note 2: You can replace the copy command (cp) with the move command (mv).

That way, all files are copied into one directory. ;-)

Linux: Executable PHP Files

24/09/2008

Another nice thing about Linux is that you don’t need to use a program command to execute a PHP script, if you have the PHP-CLI version installed.

On Windows and for a while on Linux, I used:

php -f myscript.php

This is perfectly fine, but this executable file method is best for simple tool-scripts that you want to run manually on your system.

All you need to do is include this line on the very first line of your PHP file:

#!/usr/bin/php

Note that you still need to use the <?php ?> tags, but they go after that line.

Once you edited your script, you make it executable:

chmod +x myscript.php

And to run it you go to your script’s path and use this:

./myscript.php