LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 12-05-2011, 02:14 AM   #1
cmk77
Member
 
Registered: May 2006
Location: netherlands
Distribution: slackware, centos, scientificlinux
Posts: 119

Rep: Reputation: 24
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?
 
Old 12-05-2011, 02:34 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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*
 
1 members found this post helpful.
Old 12-05-2011, 02:37 AM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 207Reputation: 207Reputation: 207
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.
 
Old 12-05-2011, 03:01 AM   #4
cmk77
Member
 
Registered: May 2006
Location: netherlands
Distribution: slackware, centos, scientificlinux
Posts: 119

Original Poster
Rep: Reputation: 24
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?
 
Old 12-05-2011, 03:18 AM   #5
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 207Reputation: 207Reputation: 207
Quote:
Originally Posted by cmk77 View Post
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

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 ?
 
Old 12-05-2011, 03:34 AM   #6
cmk77
Member
 
Registered: May 2006
Location: netherlands
Distribution: slackware, centos, scientificlinux
Posts: 119

Original Poster
Rep: Reputation: 24
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.

Last edited by cmk77; 12-05-2011 at 03:35 AM. Reason: typo
 
Old 12-05-2011, 12:13 PM   #7
cmk77
Member
 
Registered: May 2006
Location: netherlands
Distribution: slackware, centos, scientificlinux
Posts: 119

Original Poster
Rep: Reputation: 24
Well, I checked and there's no "prename" in slackware 13.0.
 
Old 12-05-2011, 12:26 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949
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
 
Old 12-05-2011, 12:51 PM   #9
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 885Reputation: 885Reputation: 885Reputation: 885Reputation: 885Reputation: 885Reputation: 885
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Traverse the file system and Rename (xargs or sed?) sahil.jammu Linux - General 19 05-25-2011 10:15 AM
[SOLVED] sed and rename text in file cober Programming 2 02-10-2011 03:30 PM
Oneline filename batch rename (specific sed instance pattern matching) briana.paige Linux - Newbie 1 11-11-2010 05:56 PM
Using Sed to Rename A Group of Files smithjb Programming 6 05-03-2009 09:27 PM
how to rename files using sed? seimour Linux - Newbie 1 05-02-2007 01:46 AM


All times are GMT -5. The time now is 11:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration