More on Rename

December 19, 2009

In the previous post I mentioned the rename command, but said that I didn’t know too much about it.   Well after some reading, and messing around I have learned a little bit more, so guess I should share.

Here is the general set up of the command;
rename [options] 's/expr1/expr2/' expr3
expr1, expr2, and expr3 are Perl regular expressions. Basically it will replace expr1 with expr2 in every file that matches expr3.
The options are;
-n (do nothing, just print out what the result would be if the command were to run)
-f (force overwrite of existing files) and
-v (verbose, print out progress while command runs).

For the sake of these example suppose that your folder contains the following files:
Pic_00019876_new.JPG
Pic_00029877_new.JPG
Pic_00039878_new.JPG
Pic_00049879_new.JPG
Pic_00059870_new.JPG

Example 1

Suppose that we want to change the file extensions to .jpg instead. Then just type rename 's/\.JPG/\.jpg/' *.JPG So instead of having Pic_00019876_new.JPG you have Pic_00019876_new.jpg

Example 2

Now suppose that you want to remove the leading 0s from the file number. For this you would type something like
rename 's/Pic_(\d{3})(\d{5})_new\.JPG/Pic_$2_new\.JPG/' *.JPG
The $2 says to use the 2nd matched group, and the (\d{X}) matches X digits.
Here Pic_00019876_new.JPG becomes Pic_19876_new.JPG

Example 3

For the hell of it say that you want to remove the ‘Pic’ prefix, make the first 4 digits the last 4, make .JPG into .jpg and put ‘new’ at the front. For this you could run
rename 's/Pic_(\d{4})(\d{4})_(new)\.JPG/$3_$2$1\.jpg/' *.JPG
One word of caution, make sure the escape the ‘.’ or you might get unexpected results. Now Pic_00019876_new.JPG becomes new_98760001.jpg

Hope that those examples were useful. the ’s/…’ says that it will be matching a string. There are other things you can use instead of ’s’, but I don’t know what they are and am not a Perl guru so I wouldn’t be able to tell you. I do however, know that ‘y/…’ is used in changing the case of all characters.

For further reading I would suggest this site.


Rename

December 15, 2009

I’m sure that many of you have experienced this before, and if not I have experienced it enough times to warrant a post.  I download an album but all the track names have extra letter either appended to the beginning or the end.  And as the name of this post suggest I would like to rename them all and remove these characters.

Sure I could use the mv command or even open up the GUI file browser and go from there, but I want to get this done with as little work as possible.  The funny thing is that I probably spent more time trying to find this solution than it would have taken if I were to actually do this the long way.

Well here is the command you need: rename.  I suggest that you read the man page for it since at this point I’m not all to sure how it works.  But I can provide you with an example of what you need to type to get the job done (in this case at least).  Suppose that the following sequence is after what you want AwX3 and they are all .mp3 files

rename -n 's/AwX3//' *.mp3

Doing this will tell you which files will be renamed and what they would be renamed to.  After you have made sure that everything is alright, run it again but this time with out the -n.

Hope this helps someone, and if not I know it will help me in the future when I have this problem again.


The TOP of the Mountain

December 8, 2009

So back to looking up processes.  I’ve previously mentioned the ps command which lets you see all the processes that are running on your system, without having to leave the comfort of the terminal.  Well top is kind of similar to that.  Instead of showing a list of running processes top shows you the jobs that are currently the most demanding on your processor.

Lets say that all of a sudden your computer starts to slow down and you aren’t sure which application/process is causing it.  Well instead of going through everything in ps aux | less, you could just look at top and figure it out from there.  The display not only tells you how much of your CPU the job is using but it also gives you the process ID (PID), which user is running the job.  Some other information is also displayed but I haven’t looked at it in too much detail so I can’t comment too much.

The output is pretty straight forward and to even help each column has its title printed along the top.

Here is a sample of what my display looks like when I entered the command:


Flash and Flashplayer 10

December 1, 2009

Let’s face it flash is a bitch.  Sadly lots of web pages make use of it.

So if you are using a 64bit architecture then you are almost always shit out of luck.  Well there is finally a way to get around this.  Yes I know that this isn’t anything new, but I haven’t had a need to update until recently.  So naturally I went to Google (if you haven’t picke up on the pattern here by now then I don’t know what’s wrong with you) and took a look around.  Most of the results were restatements of the same method (which didn’t work by the way).  However, I did manage to find one that did, here is the link to the site.  Just in case anyone else might need it.

I’ll say it once again, flash is a bitch.


More on Facebook and Pidgin

November 12, 2009

Well Facebook has up and gone and changed their way of logging in (or something along those lines). For this reason I was not able to connect to my facebook account through Pidgin. As a result I just didn’t talk to some of my friends for a while. Don’t ask me why they believe that facebook-chat is much better than say AIM and GoogleTalk.
However, thanks to the Ubuntu forums (if you haven’t been here yet and you use Ubuntu, what is wrong with you) and Google I was able to solve the problem. I’ve said it before and I’ll say it again: “For a beginning Linux, user Google is your BEST FRIEND!”

Well without further delay, here is a solution.  First get close Pidgin, then run sudo apt-get remove pidgin-facebookchat.  This will remove your old version of the package. In addition you will need to remove your libjson-glib-1.0-0 package.  I suggest using the package manager for this (System>>Administration>>Synaptic Package Manager) to do this, only because I don’t remember the exact package name.

Now you all you have to do is download the new packages. The libjson-glib package can be found at http://mirror.ne.gov/ubuntu/pool/universe/j/json-glib/ from this list of files I selected libjson-glib-1.0-0-dbg_0.7.6-0ubuntu1_amd64.deb, your choice will depend on if you are using a 64bit or 32bit processor.  If you are using 64bit use the file listed above, for you 32bit users choose the ones that ends in i386.deb.  Finally to get the facebookchat plugin go to this site: http://code.google.com/p/pidgin-facebookchat/downloads/list and download the most recent version.

At this point I assume that everything is saved to your Desktop.  First right click on the libsjon file, and select “Open with GDebi Package Installer”.  If you don’t have GDebi Package Installer, then head over to the package manager and get it, or use apt-get install.  Or you could install it yourself, but I find using this tool to much easier and less time consuming.  Now that you have the correct libjson-glib file installed, repeat the process except to the pidgin-facebookchat file.

Start up Pidgin and re-enter your login information and it is back to “business” as usual.


Halt

October 8, 2009

Sorry, I haven’t updated in a while. Sadly this won’t change anytime soon. I am extremely busy at the moment. Having to split time between classes, a job, graduate school applications, fellowship applications, and GRE preparation.

So until further notice (probably mid November) don’t expect to many, if any, updates. Thanks.


Linux File System: Part 3

September 15, 2009

Well sorry it has taken so long but here is the third installation in the series on the Linux file system. In case you haven’t been following before now, here are the links to part1 and part2.

In this portion I will discuss the following directories/partitions: /lost+found /lib /mnt and /tmp.

/lost+found

So you are working and all of a sudden there is a power outage. Or even worse your system suddenly crashes for no reason. Well the next time you boot up your machine Linux will try to recover any lost data/files. The result of this recovery attempt will be saved here. Sure the files in here might not make much sense but there is a small chance that there might be something that you might be able to actually use. Finally, for those of you that really want to know, this recovery is done by using the fsck command. Look into it yourself, since this isn’t the place to go into depth on it.

/lib

The location of all the shared library files. Think DLL files on Windows.

/mnt

This is the generic place to mount other file systems. Such as internal/external hard drives, CD-ROMS, DVD, and floppy disk if people still use those. For more information on mounting see the link to the post dedicated to this topic.  But I should mention that you can make any location a mount point, but it’s usually a good idea to have them all relatively “close” to each other.  Plus try not to overdo it, because really 50 different mount points might just be a little excessive.

/tmp

Temporary files are stored here. In other words, DON’T SAVE IMPORTANT STUFF HERE! This directory is cleared upon each reboot of the system. As a side note, this is really useful for getting around disk quotas. Just save your files here and then when you restart they will be gone. All you have to do is make sure that you won’t be needing those files ever again.


File Transfer and SSH

September 10, 2009

Well I’m not going to explain what SSH is (mainly because I would not do it much justice), so instead I will direct you to these pages if you wish to find out more. Suso Technology Services Inc. and Wikipedia.

Now suppose you want to SSH into a remote computer (one that I hope you know the name of) it is “pretty easy”. For this let us say that on that computer your username is NewKid and the host computer is FarAway.Land.ofDreams.

Then to connect to it from your computer you just enter

ssh NewKid@FarAway.Land.ofDreams

If prompted for a password then enter it. And look you are now connected.  At this point you will be able to perform whatever you want on the other computer.  However, there is no GUI so hope you like command line (which by now you should).

Now a lot of good this would do if you weren’t able to send and receive files between the two computers.  Suppose there is a file ~/urgent that you need to send to the remote computer, and wish to place it on the Desktop (~/Desktop).  Well you are in luck there is a simple way to do this.

scp ~/urgent NewKid@FarAway.Land.ofDreams:~/Desktop

There is a space between ~/urgent and NewKid… Note that if you had instead entered

scp ~/urgent NewKid@FarAway.Land.ofDreams

The file would have been placed in the home folder on the remote computer.

Now instead let us assume that ~/urgent was on the remote computer and we needed it on the local one (the one we are physically at).  In this case we run

scp NewKid@FarAway.Land.ofDreams:~/urgent ~/Desktop

Here we have copied ~/urgent to our Desktop. Similarly if we had not put ~/Desktop it would have been copied to our home directory.

Overall the usage of scp is

scp [user@from-host]:source [user@to-host]:destination

Really this post is as much a reference for me as it is a learning tool for others. Since I know that I will need to be sending and getting files quite often in the near future and am pretty sure that I will forget how right before I need to start. But hopefully, I will get back to talking about the Linux file system soon enough. Sorry for the ’side post’, but I really do hope that someone will find it useful.


Linux File System: Part 2

September 7, 2009

This is a continuation from part 1, so you might want to read that first in order to get a general idea of what’s going on.  That is  of course you are a somewhat experienced Linux user.

In this part of the series I will be discussing the following directories/partitions: /bin /boot /dev /etc /home.

/home

I will start by discussing the partition that is most familiar to most new users, /home.  First you should know that Linux, unlike Windows, was originally designed to be a multi-user system.  Thus in the home directory you will find a set of directories, one for each user.  Every user (along with the system administrator) can access their directory by entering cd /home/[user name].  Each user’s home directory contains their own personal files in addition to their personal settings for programs.

/bin

This directory contains programs that are able to be used by the system(Linux), the administrator and non-privileged users. Examples of such programs would include cp, mv, rm, and other such commands/programs. In addition to programs it also contains the shells, like bash, csh, sh, and so on. Just as a side note, you should be aware that there is also a /usr/bin which also contains programs that the system, administrator, and non-privileged users can use. However, unlike those in /bin, these programs are not essential-meaning that you can do without them and not have any real problems. Some programs that are located in my /usr/bin are: g++, apt-get, javac, whoami, and acroread. Sure it would be a pain not having these programs, but the system would still run perfectly fine.

/boot

All of the system startup files and the kernel (vmlinuz) are located in this directory (also I would suggest reading the Wikipedia article on System.map, which is also stored in this directory). On Ubuntu, this is also where Grub (GRand Unified Boot loader) stored.  For those of you that are dual-booting here is something that might interest you.  When you start up your system you will normally see a list asking you which OS you want to enter.  This list normally contains the various Linux kernels along with Windows (or whatever OS you have on your computer).  If you would like to change the order these elements are presented along with other properties here is what you need to do.  cd /boot/grub then sudo gedit menu.lst (actually you can use whatever text editor you desire)  The file is pretty well documented so editing it is pretty straight forward.

/dev

All computers have hardware, and this is where the information on all your hardware is stored. Once again let me reiterate that EVERYTHING is a file (or directory but I don’t distinguish between them in this case). If you list all of the files here, you should find sda, sda1, sda2… which represent the partitions of you master drive (instead of sda you might have hda depending on your drive type). Also you might see a files /dev/cdrom and /dev/fd or (/dev/fd0). These represent your CDROM and floppy drive (if you have them that is, because really who still has a floppy drive?). Here is something “cool” that you should all try (don’t worry it won’t damage your computer. I have done it on mine if that makes you feel any better). The file /dev/dsp represents your speakers (or whatever sound output device you have). So anything written to this file will be redirected to your speakers and played for you to hear. Thus if you run cat ~/funfile.java > /dev/dsp you will hear what funfile.java “sounds like”, assuming that you have a file called funfile.java in your home directory. Pretty cool hu?

/etc

Finally, I will slightly discuss the /etc directory.  One overview that I read, described this directory as the Linux equivalent to the Control Panel in Windows.  Basically most of the important configuration files are located here.  There are a lot of important files here that have to do with system start up (one being /etc/rc.d which contains the startup scripts for the system). It is always a good idea to back up your system, but this file more than any other I would say should really be backed up. Doing so would save you a lot of headache later when you have to reconfigure your settings, because you reinstalled your system or somehow managed to lose your installation.

Well that’s all there is for part 2. Hope you will stick around for part 3.


Linux File System: Part 1

September 5, 2009

You just moved over from Window and are now working with Ubuntu.  The only problem is that you have no idea how the file system is laid out.  In Windows you know that there are partitions D:\ (usually the recovery partition/drive) and C:\ (which acts like the main partition/drive).  Even further, these partitions are visible when you boot up your computer so you don’t have to worry about mounting them.

Now as for a Linux system, EVERYTHING IS A FILE!!! (and if it isn’t a file it’s a process).  Directories like /home (similar to C:\Users\[user name] in Windows) is just a special kind of file, that contains “pointers” do it descendants.  At this point I should mention that in Linux the file system is set up like a tree, with root node /.  Those of you that are familiar with working in DOS will have to get use to using / to navigate between directories and not \.  Really it’s not that hard to do, but does take some getting used to.  And if you are going to say “Why does Linux not adhere to the standard?” Just remember that Linux is based off of Unix which has been around much longer than Windows.  Additionally Windows doesn’t have a great track record when it comes to adhering to standards (IE for example).  Something else to keep in mind is that file names are case sensitive.  That means that THIS.txt is different from tHiS.txt or This.txt and even this.txt.  In Windows this isn’t the case (Thanks Kevin telling me this.  I always entered file names as if they were case sensitive when working with Windows.)

Remember earlier when I said that under Windows you don’t have to mount drives/partitions once you boot up the system?  Well under Linux you don’t have this convenience.  However, there are some advantages to this set up, so you shouldn’t cry too much.  For instance the /usr (the file that contains most of the system executables, I’ll talk about this more later) can be mounted from another computer on your network and everything will work just fine.  Just try moving the folder C:\WINDOWS to another location (have fun fixing your registry errors if you actually do this by the way).  The reason this will work under Linux is because it will still see /usr as a local directory that’s part of the local directory structure.

It is finally time to talk about the different parts of the Linux file system. To see what the directories under / are just go to that directory and enter ls -p. The entries with a / after them are directories, everything else is just a regular file.
On my system the list of directories is:

/bin /boot /dev /etc /home /initrd /lib /lib32 /lost+found /media /mnt /opt /proc /root /sbin /srv /sys /tmp /usr /var

The /lib32 directory seems to be special to 64-bit machines so I won’t be talking about it. However, I figure that it is similar to /lib, but provides support for 64-bit systems.

In part 2-and part 3, if it is needed, I will discuess each of these directories.  Nothing too detailed but it should provide you with a good starting point.