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.