How to automatically change to directories with very long full path using easy to remember aliases

2 comments

My laptop's 160GB hard disk is partitioned into more than six logical partitions and I multi-boot Windows 7, Windows XP, Kubuntu, Mandriva and Fedora. So you can imagine how I must have butchered the 160GB. I have managed to logically organize my files on the system, I put my iso image files in Kubuntu and Mandriva, my documents are in Windows XP and Windows 7. This makes it inevitable for me to frequently access documents on the Windows partitions and also copy documents to them while working in Linux. Occasionally, while working in commandline I need to mount images on the Kubuntu partition or read a file I saved in the Windows partition. Unfortunately, Fedora has a terrible way of naming my partitions that are not part of its filesystem, for example the full path to my Windows XP partition is /media/8E9C64209C640555 and the one for my Windows 7 partition is /media/925C181C5C17F9A5. After getting sick of having to copy and paste the path, I decided to do something permanent that will help me get round the problem.
Well what I eventually did was to add a four aliases to automatically change to any partition without bothering about its full path. All I did was to edit the /home/freeman/.bashrc file, I appended the following --
# User specific aliases and functions
alias kubuntu='cd /media/0f83fb7e-7810-489d-ad1d-1cfeb50e1ff2'
alias mandriva='cd /media/d06a0246-9501-4e55-8162-146e500cd2a0'
alias windowsxp='cd /media/8E9C64209C640555'
alias windows7='cd /media/925C181C5C17F9A5'

Voila! Now everytime I enter windowsxp on my command prompt, I am automatically switched to the Windows XP partition.

Interactive script to mount iso images

0 comments

My laptop's DVD drive is bad, so I prefer copying images of CD/DVDs through a friends computer DVD drive and pasting it in my cd_image folder (a special folder I created for just iso images).
The command I use for copying CD/DVD images is
dd if=/dev/sr0 of=/home/freeman/cd_image/cdname.iso
This command is pretty straight forward,  the dd stands for disk dump, if stands for input file and of stands for output file. I do not have problem with remembering the command. But I often have problem remembering the exact mount options for iso file (which is the cd image file).
So I decided to write a shell script for interactively mounting any iso image in any mount point point (which is often an empty folder).
The following is a step-wise description of the shell creation

STEP 1
I created a special folder in my home folder and named it shell, using the following command
[freeman@freeman ~]$ mkdir shell
I changed directory to the shell subdirectory I just created
[freeman@freeman ~]$ cd shell

STEP 2
I created a new file (named it mountiso) and entered the script in in using vi editor
[freeman@freeman shell]$ vi mountiso
#!/bin/bash
#This shell is for mounting cd images from anywhere to any empty folder
echo -n "Enter the full path of the iso image: "
read image
echo -n "Enter the full path of the mount point, an empty folder: "
read folder
mount -t iso9660 -o loop $image $folder
exit 0

STEP 3
I made the mountiso file executable by changing it's file permissions
[freeman@freeman shell]$ chmod a+x mountiso
I also included the /home/freeman/shell path in the PATH environment variable
[freeman@freeman shell]$ PATH=$PATH:/home/freeman/shell
To make is global, I exported the new PATH
[freeman@freeman shell]$ export PATH

So that was all, to run the new script I just enter mountiso (regardless of my current working directory) and enter both the image location and mount point without bothering about the mount options.

 
Follow me on Twitter | About me | Terms of Service | Privacy Policy