LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   rename with sed in 13.0 (http://www.linuxquestions.org/questions/slackware-14/rename-with-sed-in-13-0-a-917183/)

cmk77 12-05-2011 02:14 AM

rename with sed in 13.0
 
Using slackware 13.0 (64bit) and trying to replace foo by bar in some filenames using rename with sed-like syntax:
Code:

rename 's/foo/bar/' *foo*
doesn't seem to work. Is it supposed to? Perhaps rename in slackware is not the same as, say, rename in ubuntu where it works like this?

colucix 12-05-2011 02:34 AM

You may discover which flavour of the rename command you have by looking at the man page. The Debian and Ubuntu version is a perl script that uses a sed-like syntax. Other systems, like all the RPM-based ones, have a different command syntax:
Code:

NAME
      rename - Rename files

SYNOPSIS
      rename from to file...

where from is the string to change and to is the replacement. If this is the case, your command should read:
Code:

rename foo bar *foo*

jhwilliams 12-05-2011 02:37 AM

Ah yes... I remember coming across this too.

There's a shitty version of rename on some systems, which behaves like this: http://linux.about.com/library/cmd/blcmdl1_rename.htm

The version you want is a perl script. I believe it might actually be part of the Perl distribution.

cmk77 12-05-2011 03:01 AM

yes, I think that's the one on slackware. I would like the perl rename instead.
I have a full install of 13.0 (but without kde), where would I find the perl rename?

jhwilliams 12-05-2011 03:18 AM

Quote:

Originally Posted by cmk77 (Post 4542350)
yes, I think that's the one on slackware. I would like the perl rename instead.
I have a full install of 13.0 (but without kde), where would I find the perl rename?

I'm not sure -- it doesn't appear to be part of a Ubuntu package :confused:

Code:

dpkg-query: no path found matching pattern /usr/bin/rename.
Well, here's a copy: http://www.volkerschatz.com/unix/scripts/rename

It might be from CPAN ?

cmk77 12-05-2011 03:34 AM

Thanks! I'll give it another name (the original might be used in various slackware scripts and I don't want to break anything).
By the way, this is on ubuntu 10.04
Code:

$ ls -l /usr/bin/rename
lrwxrwxrwx 1 root root 24 2010-12-08 18:07 /usr/bin/rename -> /etc/alternatives/rename
$ ls -l /etc/alternatives/rename
lrwxrwxrwx 1 root root 16 2010-12-08 18:07 /etc/alternatives/rename -> /usr/bin/prename
$ dpkg-query -S prename
perl: /usr/bin/prename

so you were right.
I'm not on slackware now but I'll try to find "prename" later.

cmk77 12-05-2011 12:13 PM

Well, I checked and there's no "prename" in slackware 13.0.

David the H. 12-05-2011 12:26 PM

The debian rename comes bundled with the perl package itself. It's officially included as /usr/bin/prename, but is linked to /usr/bin/rename through /etc/alternatives.

(Come to think of it, could it perhaps even come standard with all perl installations, and just isn't set as the default on other distros?)

It also appears to have had several updates and improvements since the version in the above link. The version I have installed appears to be this one:

https://gist.github.com/995151

ruario 12-05-2011 12:51 PM

You can just copy it over from an Ubuntu or Debian installation (its only a 3Kb file). I just tried it and it runs find on Slackware 13.37.


All times are GMT -5. The time now is 11:19 AM.